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

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


显示windows通用对话框

dialogObject.ShowDialog();

示例代码:

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;
   9:  
namespace CommonDialog
  11: {
class FormMain : Form
  13:     {
public FormMain()
  15:         {
  16:             InitializeComponent();
  17:         }
  18:  
object sender, EventArgs e)
  20:         {
  21:             colorDialog1.ShowDialog();
  22:             txtShow.BackColor = colorDialog1.Color;
  23:         }
  24:  
object sender, EventArgs e)
  26:         {
  27:             fontDialog1.ShowDialog();
  28:             txtShow.Font = fontDialog1.Font;
  29:         }
  30:  
object sender, EventArgs e)
  32:         {
  33:             folderBrowserDialog1.ShowDialog();
  34:             txtShow.Text = folderBrowserDialog1.SelectedPath;
  35:         }
  36:     }
  37: }

相关文章:

  • 2021-10-17
  • 2021-08-31
  • 2021-10-16
  • 2021-08-21
  • 2021-05-05
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-15
  • 2021-07-19
  • 2021-03-26
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案