开发者

Change the status of a panel within a class

I am having a windows form applic开发者_如何学Pythonation which contains a panel. I want to access that panel when I call a specific method in a class file and change the status of the panel to visible.

I tried to create an object of the form within the method and change the status. It does not gives an error, but it does not display the panel.

public class Compare
{
  public void Comp(a,b)
  {
     form1 f=new form1();

     if(a<b)
        f.panel1.visible=true;
     else if(a>b)
        f.panel2.visible=true;
     else
        f.panel3.visible=true;
  }
}

Can anyone tell me how to do this in C#?

Thanks in advance.


is the panel also added to the form1?

f.Controls.Add(panel1);


Does the form already exist before you run Comp?

You can't make a new form and expect it to reference to your main form. You have to add another parameter to Comp, like this:

public void Comp(form1 f,a,b)
{
 if(a<b)
    f.panel1.visible=true;
 else if(a>b)
    f.panel2.visible=true;
 else
    f.panel3.visible=true;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜