winform的几种常用对话框
保存文件对话框:
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
sfd.Filter = "文本文件|*.txt|配置文档|*.ini";
sfd.FileName = "newName";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Do Save
}
选择文件对话框:
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
ofd.Filter = "文本文件|*.txt|所有文件|*.*";
ofd.FileName = "";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
}
信息提示弹框:
MessageBox.Show("这是一条测试信息");
MessageBox.Show("这是一条测试信息","注意");
if (MessageBox.Show("这是一条测试信息", "Attenation", MessageBoxButtons.YesNo) == DialogResult.Yes) { }
文本输入弹框:
using Microsoft.VisualBasic;//引入命名空间
string newPlace = Interaction.InputBox("请输入信息!", "111", "222");
颜色选择对话框:
ColorDialog cd = new ColorDialog();
cd.Color = Color.Red;
if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.BackColor = cd.Color;
}
字体设置对话框:
FontDialog fd = new FontDialog();
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.button1.Font = fd.Font;
}
打印机对话框:
PrintDialog ppd = new PrintDialog();
if (ppd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { }
文件夹选择对话框:
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { }

浙公网安备 33010602011771号