Csharp/C Sharp/GUI Windows Form/SaveFileDialog — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:33, 26 мая 2010
Содержание
Call ShowDialog method to show the dialog
<source lang="csharp">
using System; using System.Windows.Forms; class MainClass {
static void Main(string[] args) { SaveFileDialog dlg = new SaveFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { Console.WriteLine(dlg.FileName); } }
}
</source>
Set CheckFileExists to true
<source lang="csharp"> using System; using System.Windows.Forms; class MainClass {
static void Main(string[] args) { SaveFileDialog dlg = new SaveFileDialog(); dlg.CheckFileExists = true; if (dlg.ShowDialog() == DialogResult.OK) { Console.WriteLine(dlg.FileName); } }
}
</source>
Set InitialDirectory for SaveFileDialog
<source lang="csharp">
using System; using System.Windows.Forms; class MainClass {
static void Main(string[] args) { SaveFileDialog dlg = new SaveFileDialog(); dlg.InitialDirectory = Application.StartupPath; if (dlg.ShowDialog() == DialogResult.OK) { Console.WriteLine(dlg.FileName); } }
}
</source>
Use Filter in SaveFileDialog to filter file extension
<source lang="csharp"> using System; using System.Windows.Forms; class MainClass {
static void Main(string[] args) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "RichText Files (*.rtf)|*.RTF|Text Files (*.txt)|*.TXT" + "|All files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { Console.WriteLine(dlg.FileName); } }
}
</source>