C#, VB FolderBrowserDialog
19 ธันวาคม 2552
วันนี้ก็ของเสนอเกี่ยวกับการสร้าง FolderBrowserDialog แบบง่ายๆ มาใช้ในการเลือก Directory ทีเราต้องการ แบบเนียนๆ กันนะครับ ไปชม ตัวอย่าง Source Code กันเลยครับ
Source Code C#
//Namespace
//using System.Windows.Forms;
//สร้าง object SaveFileDialog.
SaveFileDialog ObjsaveFile = new SaveFileDialog();
//Title ของ Dialog.
ObjsaveFile.Title = "C# Open File Dailog";
//ตั้งค่าเริ่มต้นชื่อ File
ObjsaveFile.FileName = "Text.text";
//กรองนามสกุลไฟล์
ObjsaveFile.Filter = "Text Files|*.txt|ALL Files|*.*";
//แสดง Save File Dialog
//ObjsaveFile.ShowDialog();
//สร้าง object FolderBrowserDialog.
FolderBrowserDialog objFolderBrowserDialog = new FolderBrowserDialog();
//แสดงปุ่มสร้าง Folder ใหม่
objFolderBrowserDialog.ShowNewFolderButton = true;
//แสดงรายละเอียดของ Dialog
objFolderBrowserDialog.Description = "C# Folder Browser Dialog";
// Show the FolderBrowserDialog.
if (objFolderBrowserDialog.ShowDialog() == DialogResult.OK)
{
//นำ Path ที่ได้ไปแสดงบน TextBox
textBox1.Text = objFolderBrowserDialog.SelectedPath;
}
else
{
textBox1.Text = string.Empty;
}
Source Code VB
'Namespace
'Imports System.Windows.Forms
'สร้าง object SaveFileDialog.
Dim ObjsaveFile = New SaveFileDialog()
'Title ของ Dialog.
ObjsaveFile.Title = "VB Open File Dailog"
'ตั้งค่าเริ่มต้นชื่อ File
ObjsaveFile.FileName = "Text.text"
'กรองนามสกุลไฟล์
ObjsaveFile.Filter = "Text Files|*.txt|ALL Files|*.*"
'สร้าง object FolderBrowserDialog.
Dim objFolderBrowserDialog = New FolderBrowserDialog()
'แสดงปุ่มสร้าง Folder ใหม่
objFolderBrowserDialog.ShowNewFolderButton = True
'แสดงรายละเอียดของ Dialog
objFolderBrowserDialog.Description = "VB Folder Browser Dialog"
'Show the FolderBrowserDialog.
If (objFolderBrowserDialog.ShowDialog() = DialogResult.OK) Then
'นำ Path ที่ได้ไปแสดงบน TextBox
textBox1.Text = objFolderBrowserDialog.SelectedPath
Else
textBox1.Text = String.Empty
End If
เราก็จะได้ Dircetory ของ Folder ที่ต้องการนั้นๆ เพื่อนำไปใช้ต่อไปครับ
ผิดพลาดประการใดก็ติชมแก้ไขกันนะครับ
ขอบคุณครับ

0 ความคิดเห็น:
แสดงความคิดเห็น