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、效果展示