• 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: }
  • 相关阅读:
    【Python】使用codecs模块进行文件操作及消除文件中的BOM
    Vue公共结果页面实现
    vscode调整字体大小
    vue-cli3使用vue-svg-loader加载svg
    Microsoft Edge Chrome 下载
    [译]基于Vue.js的10个最佳UI框架,用于构建移动应用程序
    axios采坑之路
    MacBook Touch Bar 使用技巧
    vue-cli 3.x 移除console总结
    嵌入式Linux如何设置获取uboot参数
  • 原文地址:https://www.cnblogs.com/hanzhaoxin/p/2845287.html
Copyright © 2020-2023  润新知