在静态方法中设置面板可见属性true

时间:2017-07-13 08:25:56

标签: c# winforms

这里我有一个面板控件,我想在静态方法中将它的可见属性设置为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;
            }

1 个答案:

答案 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;
}