Tuesday, January 29, 2013

How to hide a Contentpane or any Controls in FormAlpha on a Button click event of FormBeta which loads as a dialog box on top of FormAlpha


Two steps are needed:
First, Form Alpha needs a public Fucntion called "hidePane()" whose sole purpose is to hide the Pane.
Second, Form Beta needs a reference to Form Alpha. I asume that Alpha creates generates Beta and shows it. In this case give Beta a constructor that takes a FormAlpha as parameter:
//Variable to store wich form created this form
FormAlpha creatorForm;

public FormBeta (FormAlpha Creator){
  InitializeComponent();
  creatorForm = Creator;
}
Instead of using the normal empty constructor to create FormBeta:
Form otherForm = new FormBeta();
otherForm.show();
use the newly created one and give it a Reference to Alpha with "this":
Form otherForm = new FormBeta(this);
otherForm.Show();
now all your ButtonClick even has to do is call the hidePanle():
creatorForm.hidePanel();
P.S. if you want to be able to unhide he Panel as well, we may have to change step 1 a little.

No comments:

Post a Comment