AutoSize:設置爲false取消自動計算尺寸功能,控件的大小則按照設定的Size來呈現,設置爲true自動計算大小this
TextAlign:設置對齊方式spa
//
// 摘要:
// 用默認的全部者運行通用對話框。
//
// 返回結果:
[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。3d
一、建立一個這樣的窗體code
二、加入ColorDialog控件orm
三、編寫按鍵程序blog
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的前景顏色 } } } }
四、效果展現get