先来效果,重在吸取其精华,加油!

主要代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace CommonDlgs
{public partial class Form1 : Form{public Form1( ){InitializeComponent( );}//依次显示4个不同类型的消息框。private void btnMsgBox_Click(object sender, EventArgs e){MessageBox.Show("这是第一个消息框,只有确认按钮");                          //显示最简单的MessageBoxMessageBox.Show("这是第二个消息框,有标题,只有确认按钮", "第二个消息框");   //显示有文本和标题的MessageBox//显示具有文本、标题、确定和取消按钮的MessageBoxMessageBox.Show("这是第三个消息框,有标题,只有确认和取消按钮", "第三个消息框",  MessageBoxButtons.OKCancel);  //显示具有文本、标题、确定和取消按钮、告警图标的MessageBoxMessageBox.Show("这是第四个消息框,有标题,只有确认和取消按钮,告警图标", "第四个消息框", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);}private void btnOpenFile_Click(object sender, EventArgs e){OpenFileDialog ofdlg = new OpenFileDialog( );                   //创建OpenFileDialog对象ofdlg.Filter = "文本文件(*.txt)|*.TXT|Word文件(*.doc)|*.DOC"; //只选择TXT和DOC扩展名文件ofdlg.Title = "选择文本文件或Word文件";                      //设置对话框的标题if(ofdlg.ShowDialog() == DialogResult.OK)                       //显示对话框,并等待返回{this.tbOpenFileName.Text = ofdlg.FileName;                  //如果用户选择了文件则显示到界面}else{this.tbOpenFileName.Text = "还没有选择要打开的文件";     //没有选择文件,则显示默认提示}}private void btnSetColor_Click(object sender, EventArgs e){ColorDialog cdlg = new ColorDialog( );                          //创建ColorDialog对象cdlg.Color = btnSetColor.ForeColor;                             //设置默认颜色为btnSetColor当前前景色if (cdlg.ShowDialog( ) == DialogResult.OK)                      //显示对话框,并等待返回{this.btnSetColor.ForeColor = cdlg.Color;                    //选择了新的颜色,则更新btnSetColor前景色}}private void btnSaveFile_Click(object sender, EventArgs e){SaveFileDialog sfdlg = new SaveFileDialog( );                   //创建SaveFileDialog对象sfdlg.Filter = "文本文件(*.txt)|*.TXT";                        //默认扩展名为*.TXTsfdlg.Title = "请选择或输入要保存的文本文件";if(sfdlg.ShowDialog() == DialogResult.OK)                       //显示对话框,并等待返回{this.tbSaveFileName.Text = sfdlg.FileName;                  //如果用户选择了文件则显示到界面}else{this.tbSaveFileName.Text = "还没有选择要保存的文件";     //没有选择文件,则显示默认提示}}private void btnSetFont_Click(object sender, EventArgs e){FontDialog fdlg = new FontDialog( );                          //创建FontDialog对象fdlg.Font = btnSetFont.Font;                             //设置默认字体为btnSetFont当前字体if (fdlg.ShowDialog( ) == DialogResult.OK)                      //显示对话框,并等待返回{this.btnSetFont.Font = fdlg.Font;                    //选择了新的字体,则更新btnSetFont的字体}}}
}

控件标注代码如下:

namespace CommonDlgs
{partial class Form1{/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的资源。/// </summary>/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose( );}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法 - 不要/// 使用代码编辑器修改此方法的内容。/// </summary>private void InitializeComponent( ){this.btnMsgBox = new System.Windows.Forms.Button( );this.btnOpenFile = new System.Windows.Forms.Button( );this.tbOpenFileName = new System.Windows.Forms.TextBox( );this.btnSaveFile = new System.Windows.Forms.Button( );this.tbSaveFileName = new System.Windows.Forms.TextBox( );this.btnSetColor = new System.Windows.Forms.Button( );this.btnSetFont = new System.Windows.Forms.Button( );this.SuspendLayout( );// // btnMsgBox// this.btnMsgBox.Location = new System.Drawing.Point(12, 12);this.btnMsgBox.Name = "btnMsgBox";this.btnMsgBox.Size = new System.Drawing.Size(130, 23);this.btnMsgBox.TabIndex = 0;this.btnMsgBox.Text = "显示MessageBox()";this.btnMsgBox.UseVisualStyleBackColor = true;this.btnMsgBox.Click += new System.EventHandler(this.btnMsgBox_Click);// // btnOpenFile// this.btnOpenFile.Location = new System.Drawing.Point(12, 42);this.btnOpenFile.Name = "btnOpenFile";this.btnOpenFile.Size = new System.Drawing.Size(130, 23);this.btnOpenFile.TabIndex = 1;this.btnOpenFile.Text = "打开文件";this.btnOpenFile.UseVisualStyleBackColor = true;this.btnOpenFile.Click += new System.EventHandler(this.btnOpenFile_Click);// // tbOpenFileName// this.tbOpenFileName.Location = new System.Drawing.Point(12, 71);this.tbOpenFileName.Name = "tbOpenFileName";this.tbOpenFileName.Size = new System.Drawing.Size(439, 21);this.tbOpenFileName.TabIndex = 2;// // btnSaveFile// this.btnSaveFile.Location = new System.Drawing.Point(12, 100);this.btnSaveFile.Name = "btnSaveFile";this.btnSaveFile.Size = new System.Drawing.Size(130, 23);this.btnSaveFile.TabIndex = 1;this.btnSaveFile.Text = "保存文件";this.btnSaveFile.UseVisualStyleBackColor = true;this.btnSaveFile.Click += new System.EventHandler(this.btnSaveFile_Click);// // tbSaveFileName// this.tbSaveFileName.Location = new System.Drawing.Point(12, 129);this.tbSaveFileName.Name = "tbSaveFileName";this.tbSaveFileName.Size = new System.Drawing.Size(439, 21);this.tbSaveFileName.TabIndex = 2;// // btnSetColor// this.btnSetColor.Location = new System.Drawing.Point(171, 12);this.btnSetColor.Name = "btnSetColor";this.btnSetColor.Size = new System.Drawing.Size(132, 23);this.btnSetColor.TabIndex = 3;this.btnSetColor.Text = "设置颜色";this.btnSetColor.UseVisualStyleBackColor = true;this.btnSetColor.Click += new System.EventHandler(this.btnSetColor_Click);// // btnSetFont// this.btnSetFont.Location = new System.Drawing.Point(309, 12);this.btnSetFont.Name = "btnSetFont";this.btnSetFont.Size = new System.Drawing.Size(132, 23);this.btnSetFont.TabIndex = 3;this.btnSetFont.Text = "设置字体";this.btnSetFont.UseVisualStyleBackColor = true;this.btnSetFont.Click += new System.EventHandler(this.btnSetFont_Click);// // Form1// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(463, 165);this.Controls.Add(this.btnSetFont);this.Controls.Add(this.btnSetColor);this.Controls.Add(this.tbSaveFileName);this.Controls.Add(this.btnSaveFile);this.Controls.Add(this.tbOpenFileName);this.Controls.Add(this.btnOpenFile);this.Controls.Add(this.btnMsgBox);this.Name = "Form1";this.Text = "通用对话框实例";this.ResumeLayout(false);this.PerformLayout( );}#endregionprivate System.Windows.Forms.Button btnMsgBox;private System.Windows.Forms.Button btnOpenFile;private System.Windows.Forms.TextBox tbOpenFileName;private System.Windows.Forms.Button btnSaveFile;private System.Windows.Forms.TextBox tbSaveFileName;private System.Windows.Forms.Button btnSetColor;private System.Windows.Forms.Button btnSetFont;}
}

C#界面设计之通用对话框的使用相关推荐

  1. VC++开发垃圾文件清理软件之三:程序的界面设计与实现----对话框界面

    先说下哈,有人说要源代码,源代码在博文<VC++开发垃圾文件清理软件之四:程序的界面设计与实现----按钮控件界面>的最后给出下载地址供大家下载. 对应用程序界面的设计包括两部分,一部分是 ...

  2. java调用通用对话框,利用Java Swing设计通用对话框

    利用Java Swing设计通用对话框 分享到: 文/杨少波 在Java Swing编程中,程序员还可以自定义对话框,一般可以从JDialog类来继承.下面给出一个对话框类的代码: class Hel ...

  3. MFC 基于VLC的视频播放器(三)---界面设计以及对话框接受文件的拖拽

    北京时间23点11分 2018年12月20日 前面已经完成了vlc的环境的搭建,下面便开始真正的编程. 前面的界面是这样的: 理想的界面应该是这样的: 所以添加按钮.进度条和播放列表控件,并且修改好I ...

  4. Java图形化界面设计——容器(JFrame)

    Java图形化界面设计--容器(JFrame) 程序是为了方便用户使用的,因此实现图形化界面的程序编写是所有编程语言发展的必然趋势,在命令提示符下运行的程序可以让我们了解java程序的基本知识体系结构 ...

  5. 二级VB培训笔记07:通用对话框

    二级VB培训笔记07:通用对话框 通用对话框(CommonDialog)控件提供了一组标准对话框界面,包括打开文件.保存文件.选择颜色.选择字体.设置打印机和帮助等六个对话框.这些对话框只能返回用户输 ...

  6. (附源码)springboot电商系统前端界面设计与浏览器兼容性研究 毕业设计 231058

    基于springboot电商系统前端界面设计 摘  要 随着科学技术的飞速发展,各行各业都在努力与现代先进技术接轨,通过科技手段提高自身的优势:对于电商系统前端界面设计与浏览器兼容性研究当然也不能排除 ...

  7. 第二章 VB的界面设计

    轉自:http://wwww.hyit.edu.cn/edu/vb/study/index.htm 第二章         VB的界面设计 2.1  VB用户界面设计基础 1. 概述 界面的设计有两步 ...

  8. spring boot电商系统前端界面设计与浏览器兼容性研究 毕业设计-附源码231058

    摘  要 随着科学技术的飞速发展,各行各业都在努力与现代先进技术接轨,通过科技手段提高自身的优势:对于电商系统前端界面设计与浏览器兼容性研究当然也不能排除在外,随着网络技术的不断成熟,带动了电商系统前 ...

  9. Linux下基于GTK人脸识别界面设计

    Linux下基于GTK人脸识别界面设计 1.人脸识别简介   人脸识别,是基于人的脸部特征信息进行身份识别的一种生物识别技术.用摄像机或摄像头采集含有人脸的图像或视频流,并自动在图像中检测和跟踪人脸, ...

最新文章

  1. Win8.1下Node.js连接oracle
  2. 专访iOS开发框架BeeFramework作者郭虹宇
  3. {%csrf_token%}的作用
  4. c语言编程题笔试 博客,【笔试题】C语言:模拟实现strncmp
  5. sql server紧急状态下登录脚本
  6. 将tomcat添加到服务中
  7. Magento--判断checkout中是否使用了coupon code
  8. syntaxnet python调用
  9. ApacheCN DevOps 译文集(二)20211230 更新
  10. poj2752Seek the Name, Seek the Fame【kmp next数组应用】
  11. Java数组:随机排序
  12. RGMII2GMII 分析
  13. c语言汉字属于什么类型_C语言为什么需要定义数据类型
  14. c语言中的整型常量和实型常量
  15. Java 8 reduce 是什么
  16. 传奇开服教程:传奇添加地图花屏原因与解决方法
  17. pmp项目管理师证书有什么用?
  18. 虚拟机如何进入PE系统
  19. 现代计算机体系结构发明人,cpu的发明人是谁啊?
  20. Markdown表格中换行、合并单元格

热门文章

  1. word中如何快速添加标题格式,实现快速合稿需求,以及标题格式统一修改方法
  2. Spark GraphX 聚合操作
  3. 车载业务未起量,主力产品毛利低下,联创电子陷入“增收不增利”
  4. 计算机主板上有内存条吗6,如何判断电脑是否需要加内存条?
  5. 软件测试的重要性 j .管理学家,软件测试管理常见题及其回答.doc
  6. TDP“星星之火”计划——第三期招新启动
  7. Linux cd命令cd、 cd ~、cd /、cd../、cd /home
  8. java 基础面试题
  9. Python_剪刀石头布
  10. 计算机一级判断题2016,2016年计算机一级考试WPS基础模拟判断题