1
我做了一個新的自定義按鈕和一個新的布爾屬性。 當我在Visual Studio中將新的自定義按鈕添加到我的窗體時,設計功能很好。根據運行時新的自定義屬性初始化自定義c#控件
我想加載兩個設計取決於該布爾屬性,但父窗體已經在formdesigner.cs中的設計代碼和按鈕看起來是一樣的。
我應該重寫什麼方法來訪問按鈕的「加載」?
這是我的按鈕CS
namespace Regio.UI
{
public class MetroButton : System.Windows.Forms.Button
{
public bool Highlight { get; set; }
public MetroButton()
{
if (Highlight == true)
{
base.BackColor = Color.White;
base.ForeColor = Color.Black;
FlatStyle = FlatStyle.Flat;
FlatAppearance.BorderColor = Color.Gray;
FlatAppearance.BorderSize = 2;
FlatAppearance.MouseOverBackColor = Color.WhiteSmoke;
}
else {
base.BackColor = Color.White;
base.ForeColor = Color.Black;
base.FlatStyle = FlatStyle.Flat;
base.FlatAppearance.BorderColor = Color.FromArgb(0, 174, 219);
base.FlatAppearance.BorderSize = 3;
base.FlatAppearance.MouseOverBackColor = Color.WhiteSmoke;
}
}
}
}
這是在Form1.designer.cs:提前
this.metroButton1 = new Regio.UI.MetroButton();
this.metroButton2 = new Regio.UI.MetroButton();
this.SuspendLayout();
//
// metroButton1
//
this.metroButton1.BackColor = System.Drawing.Color.Black;
this.metroButton1.FlatAppearance.BorderColor = System.Drawing.Color.Gray;
this.metroButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.metroButton1.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.metroButton1.ForeColor = System.Drawing.Color.White;
this.metroButton1.Highlight = false;
this.metroButton1.Location = new System.Drawing.Point(212, 172);
this.metroButton1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.metroButton1.MinimumSize = new System.Drawing.Size(100, 30);
this.metroButton1.Name = "metroButton1";
this.metroButton1.Padding = new System.Windows.Forms.Padding(3);
this.metroButton1.Size = new System.Drawing.Size(171, 111);
this.metroButton1.TabIndex = 0;
this.metroButton1.Text = "metroButton1";
this.metroButton1.UseVisualStyleBackColor = false;
感謝
工作得很好,謝謝:) – TrulyXax
不客氣,任何幫助^ _ ^ – Rariolu