码迷,mamicode.com
首页 > Windows程序 > 详细

Winform 五种常用对话框控件的简单使用

时间:2016-09-27 06:55:39      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

OpenFileDialog(打开文件对话框)
FolderBrowserDialog(浏览文件夹对话框)
SaveFileDialog(保存文件对话框)
ColorDialog(颜色对话框)
FontDialog(字体对话框)

技术分享

 

技术分享
 1         private void button1_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog oFD = new OpenFileDialog();
 4             oFD.Title = "选择数据文件";//对话框标题
 5             oFD.Filter = "所有文件(*.*)|*.*|Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx";//设置文件名筛选器
 6             oFD.Multiselect = true;//是否可以多选文件
 7             if (oFD.ShowDialog() == DialogResult.OK)
 8             {
 9                 textBox1.Text = oFD.FileName;
10             }
11         }
12 
13         private void button2_Click(object sender, EventArgs e)
14         {
15             FolderBrowserDialog fBD = new FolderBrowserDialog();
16             fBD.Description = "请选择一个文件夹";//控件上显示的说明文本
17             fBD.RootFolder = Environment.SpecialFolder.Desktop;//设置开始浏览的根文件夹
18             fBD.ShowNewFolderButton = true;//是否显示“新建文件夹”按钮
19             if (fBD.ShowDialog() == DialogResult.OK)
20             {
21                 textBox2.Text = fBD.SelectedPath;
22             }
23         }
24 
25         private void button3_Click(object sender, EventArgs e)
26         {
27             SaveFileDialog sFD = new SaveFileDialog();
28             sFD.Title = "保存文件对话框";//对话框标题
29             sFD.Filter = "所有文件(*.*)|*.*|Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx";//设置文件名筛选器
30             sFD.InitialDirectory = @"C:/";//对话框显示的初始目录
31             sFD.FileName = "abc.xls";//对话框选定的文件名
32             if (sFD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
33             {
34                 this.textBox3.Text = sFD.FileName;
35             }
36         }
37 
38         private void button4_Click(object sender, EventArgs e)
39         {
40             ColorDialog cd = new ColorDialog();
41             if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
42             {
43                 this.textBox4.Text = cd.Color.ToString();
44                 //this.textBox4.Text = (cd.Color.A + ";" + cd.Color.R + ";" + cd.Color.G + ";" + cd.Color.B).ToString();
45             }
46         }
47 
48         private void button5_Click(object sender, EventArgs e)
49         {
50             FontDialog sd = new FontDialog();
51             if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
52             {
53                 this.textBox5.Text = sd.Font.FontFamily.Name.ToString();
54             }
55         }
View Code

 

 

Winform 五种常用对话框控件的简单使用

标签:

原文地址:http://www.cnblogs.com/xifengyeluo/p/5911350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!