Quesions in this.Controls.Remove()/Add() ??
-
Hi there, I hava a Form with 2 UserControls and 1 dialogBox. I want to use the DialogBox to set which UserControl will display on the Form. -UserControlA(a button: buttonToB) Form -UserControlB(a button: buttonToA) -DialogBox(2 buttons: Ok & Cancel) The Form will display UserControlA as StartUp, when buttonToB is clicked, the DialogBox appears, if Ok is pressed, then UserControlA will be removed and UserControlB will be add to the Form. I have public menthods in the Form as follows: public void RemoveUserControlA(){ this.Controls.Remove(UserControlA) // remove B UserControlA.Dispose(); } public void AddUserControlB(){ this.Controls.Add(UserControlB) } In the UserControlA, when the buttonToB is clicked private void buttonToB_click(){ if(dialog.Result == Ok){ Form f = new Form(); f.RemoveUserContorlA(); f.AddUserControlB(); } } Questions 1) How can I have some methods in the Form, and then invoke it in the UserContolA (i.e. public methods ?)? 2) How can I remove the Usercontrols using the dialog? thanks. :)