AutoSize:设置为false取消自动计算尺寸功能,控件的大小则按照设定的Size来呈现,设置为true自动计算大小
TextAlign:设置对齐方式
//
// 摘要:
// 用默认的所有者运行通用对话框。
//
// 返回结果:
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public DialogResult ShowDialog(); // System.Windows.Forms.DialogResult.OK 如果用户单击确定在对话框中;否则为 System.Windows.Forms.DialogResult.Cancel。
1、创建一个这样的窗体
2、加入ColorDialog控件
3、编写按键程序
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 设置控件前景色和背景色 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnBackColor_Click(object sender, EventArgs e) { //调用ShowDialog方法显示用于选择颜色的窗口 if (this.colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //如果单击“确认键",showDialog方法返回DialogResult.OK this.label1.BackColor = this.colorDialog1.Color;//设置label1的背景颜色 } } private void btnForeColor_Click(object sender, EventArgs e) { if (this.colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.label1.ForeColor = this.colorDialog1.Color;//设置label1的前景颜色 } } } }
4、效果展示