我想要一個從基礎面板繼承的面板,無論使用何處,都要有固定的BackColor
。我的基本面板看起來是這樣的:如何防止控件的BackColor被更改?
public class MyPanel
{
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = Color.Red;
}
}
}
的BackColor
沒有在Designer.cs
文件中的示例表格設置:
this.sampleControl.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.sampleControl.Location = new System.Drawing.Point(0, 0);
this.sampleControl.Margin = new System.Windows.Forms.Padding(5);
this.sampleControl.Name = "sampleControl";
this.sampleControl.Padding = new System.Windows.Forms.Padding(2, 0, 2, 2);
this.sampleControl.Size = new System.Drawing.Size(230, 100);
this.sampleControl.TabIndex = 1;
其實是沒有顏色的任何地方設定,所以我想它在某種程度上得到它被放置在面板上的財產。我怎樣才能防止這種情況?
有什麼實際的顏色,你看到了什麼? – ken2k 2012-02-14 16:48:17
父控件的背景色,即如果父面板是藍色,則此控件也將爲藍色。 – xsl 2012-02-14 16:49:49