Fork me on GitHub

C#学习笔记——通用对话框

Visual Studio提供的通用对话框控件有:ColorDialog、FolderBrowserDialog、FontDialog、OpenFileDialog、SaveFileDialog、PageSetupDialog、PrintDialog和PrintPreviewDialog。

在使用这些中的某个“通用对话框”控件时,可以向窗体添加该控件,并将其放在控件托盘上。可以保留这些控件的默认名字。如colorDialog1和fontDialog1,因为每种类型只有一个控件可以使用。


显示windows通用对话框

dialogObject.ShowDialog();

示例代码:

   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.Windows.Forms;
   9:  
  10: namespace CommonDialog
  11: {
  12:     public partial class FormMain : Form
  13:     {
  14:         public FormMain()
  15:         {
  16:             InitializeComponent();
  17:         }
  18:  
  19:         private void btnColor_Click(object sender, EventArgs e)
  20:         {
  21:             colorDialog1.ShowDialog();
  22:             txtShow.BackColor = colorDialog1.Color;
  23:         }
  24:  
  25:         private void btnFont_Click(object sender, EventArgs e)
  26:         {
  27:             fontDialog1.ShowDialog();
  28:             txtShow.Font = fontDialog1.Font;
  29:         }
  30:  
  31:         private void button1_Click(object sender, EventArgs e)
  32:         {
  33:             folderBrowserDialog1.ShowDialog();
  34:             txtShow.Text = folderBrowserDialog1.SelectedPath;
  35:         }
  36:     }
  37: }
posted @ 2013-01-05 10:16  韩兆新  阅读(2152)  评论(0编辑  收藏  举报