1. 對於打開文件對話框處理 #region 打開文件對話框 string StrPath; OpenFileDialog Flag = new OpenFileDialog(); Flag.Multiselect = true;//設置多選 Flag.Title = "打開文件"; //獲取或設置 ...
1. 對於打開文件對話框處理
#region 打開文件對話框
string StrPath;
OpenFileDialog Flag = new OpenFileDialog();
Flag.Multiselect = true;//設置多選
Flag.Title = "打開文件"; //獲取或設置文件對話框標題
Flag.FilterIndex = 2;//設置預設顯示文件類型為Csv文件(*.csv)|*.csv
Flag.InitialDirectory = "D:\\"; //設置初始路徑
Flag.Filter = "csv files (*.csv)|*.csv|ALL files (* .*)|* .*"; //設置“另存為文件類型”或“文件類型”框中出現的選擇內容
Flag.RestoreDirectory = true; //設置對話框是否記憶上次打開的目錄
if (Flag.ShowDialog() == DialogResult.OK)
{
StrPath = Flag.FileName;
MessageBox.Show(StrPath);
}
#endregion
2. 保存文件的對話框處理
#region 保存文件對話框
StreamWriter MyStream;
SaveFileDialog SaveFlag = new SaveFileDialog();
SaveFlag.FileName = "保存";//設置預設文件名
SaveFlag.DefaultExt = "CSV";//設置預設格式(可以不設)
SaveFlag.AddExtension = true;//設置自動在文件名中添加擴展名
SaveFlag.Filter = "csv files (*.csv)|*.csv|ALL files (* .*)|* .*";
SaveFlag.RestoreDirectory = true;
if (SaveFlag.ShowDialog() == DialogResult.OK)
{
string StrName;
StrName = SaveFlag.FileName;
MyStream = new StreamWriter(SaveFlag.FileName);
MyStream.Write(textBox1.Text);
MyStream.Flush();
MyStream.Close();
}
#endregion
3.顏色對話框的處理
#region 顏色對話框
ColorDialog colorDialog1 = new ColorDialog();
colorDialog1.AllowFullOpen = false;
colorDialog1.Color = Color.Red;
colorDialog1.ShowHelp = true;
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.BackColor = colorDialog1.Color;
}
#endregion
4.字體的對話框處理
#region 字體對話框
FontDialog FontDialog = new FontDialog();
FontDialog.Font = textBox1.Font;
FontDialog.Color = textBox1.ForeColor;
if (FontDialog.ShowDialog() != DialogResult.Cancel)
{
textBox1.Font = FontDialog.Font;
textBox1.ForeColor = FontDialog.Color;
}
#endregion