码迷,mamicode.com
首页 > 其他好文 > 详细

P92认识对话框

时间:2016-08-21 16:48:56      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace P92认识对话框
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19         //选择文件
20         private void button1_Click(object sender, EventArgs e)
21         {
22             //设置对话框标题
23             this.openFileDialog1.Title = "选择数据文件";
24             //按照扩展名过滤文件
25             this.openFileDialog1.Filter = "Excle文件|*.xls;*.xlsx|所有文件|*.*";
26             //是否支持多选
27             this.openFileDialog1.Multiselect = true;
28             if (this.openFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
29             {
30                 this.textBox1.Text = this.openFileDialog1.FileName;
31             }
32         }
33         //选择文件夹
34         private void button2_Click(object sender, EventArgs e)
35         {
36             //设置对话框的描述
37             this.folderBrowserDialog1.Description = "请选择一个文件夹";
38             //设置对话框的初始目录
39             this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;
40             //是否选择新建文件夹
41             this.folderBrowserDialog1.ShowNewFolderButton = true;
42             if (folderBrowserDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
43             {
44                 this.textBox2.Text = folderBrowserDialog1.SelectedPath;
45             }
46         }
47         //保存文件
48         private void button3_Click(object sender, EventArgs e)
49         {
50             SaveFileDialog sfd = new SaveFileDialog();
51             sfd.Title = "保存到处文件";
52             sfd.InitialDirectory = @"\d:";
53             sfd.FileName = "哈哈哈.txt";
54             sfd.Filter = "记事本|*.txt|所有问价|*.*";
55             if (sfd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
56             {
57                 this.textBox3.Text = sfd.FileName;
58             }
59         }
60 
61         private void button4_Click(object sender, EventArgs e)
62         {
63             ColorDialog cd = new ColorDialog();
64             if (cd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
65             {
66                 this.textBox4.Text = cd.Color.ToString();
67             }
68         }
69 
70         private void button5_Click(object sender, EventArgs e)
71         {
72             FontDialog fd = new FontDialog();
73             if (fd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
74             {
75                 this.textBox5.Text = fd.Font.ToString();
76             }
77         }
78     }
79 }

 

P92认识对话框

标签:

原文地址:http://www.cnblogs.com/gx-143/p/5792923.html

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