红尘夜未央

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  1 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks

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

posted on 2019-09-30 14:21  红尘夜未央  阅读(257)  评论(0编辑  收藏