C# Winform 打开文件颜色字体目录对话框实例
作者:C/S框架网  发布日期:2018-08-13 19:59:54
  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





点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇