C#, VB SaveFileDialog
18 ธันวาคม 2552
วันนี้ก็ของเสนอเกี่ยวกับการสร้าง SaveFileDialog แบบง่ายๆ มาใช้ในการ Save File ของเราแบบเนียนๆ กันนะครับ ไปชม ตัวอย่าง 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
if (ObjsaveFile.ShowDialog() == DialogResult.OK)
{
//นำ Path ที่ Save ไปแสดงบน TextBox
textBox1.Text = ObjsaveFile.FileName;
}
else
{
//นำค่าว่าง ไปแสดงบน TextBox
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|*.*"
'แสดง Save File Dialog
If ObjsaveFile.ShowDialog() = DialogResult.OK Then
'นำ Path ที่ Save ไปแสดงบน TextBox
textBox1.Text = ObjsaveFile.FileName
Else
'นำค่าว่าง ไปแสดงบน TextBox
textBox1.Text = String.Empty
End If
เพียงเท่านี้ เราก็จะได้ Directory File Name ของ File ที่ต้องการ Save หรือประยุกต์ใช้ เพื่อนำไปใช้ต่อไปครับ
ผิดพลาดประการใดก็ติชมแก้ไขกันนะครับ
ขอบคุณครับ

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