这里我有一个面板控件,我想在静态方法中将它的可见属性设置为true或False。是否有可能这样做。
private System.Windows.Forms.Panel panel1;
this.panel1 = new System.Windows.Forms.Panel();
this.panel1.Location = new System.Drawing.Point(404, 317);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 100);
this.panel1.TabIndex = 3;
public static void setPanelVisible(bool blnVisible)
{
panel1.Visible = blnVisible;
}
答案 0 :(得分:2)
在static
方法中,您只能将属性设置为static
控件。因此,如果您想使用static
方法为面板设置属性,则应将面板声明为static
本身:
private static System.Windows.Forms.Panel panel1;
另一种选择是将控件本身作为参数传递给static
方法:
public static void setPanelVisible(bool blnVisible, System.Windows.Forms.Panel panel)
{
panel.Visible = blnVisible;
}