C# Winform 打开文件颜色字体目录对话框实例
C# Winform 打开文件颜色字体目录对话框实例
本实例演示打开常用的四种对话框:
打开字体对话框
打开颜色对话框
打开文件对话框
打开目录对话框
C# Code:
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//打开字体对话框
FontDialog dlg = new FontDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.Font.FontFamily.Name);
MessageBox.Show(dlg.Font.Size.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
//打开颜色对话框
ColorDialog dlg = new ColorDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.Color.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
//打开文件对话框
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.FileName);
}
}
private void button4_Click(object sender, EventArgs e)
{
//打开目录对话框
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.SelectedPath);
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//打开字体对话框
FontDialog dlg = new FontDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.Font.FontFamily.Name);
MessageBox.Show(dlg.Font.Size.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
//打开颜色对话框
ColorDialog dlg = new ColorDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.Color.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
//打开文件对话框
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.FileName);
}
}
private void button4_Click(object sender, EventArgs e)
{
//打开目录对话框
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dlg.SelectedPath);
}
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网