Generally on forum I have seen so many times same question has been asked, “How
to call One user control from another user control
Lets See how to do that
User controls are always found in project “WindowsFormsControlLibrary”, whenever
we have to make new user controls we have to add this project to our current
project.
Our aim is to take one user control on form on form load and calling other one
from same
- Add windowsFormsControlLibrary project to
our C# project
- Add reference of
windowsFormsControlLibrary project to our Forms project and add name space
for same
- And on form load do following
UserControl1
first = new
UserControl1();
this.Controls.Add(first);
- Now suppose there is a button on
UserControl1 and we need to call another user control having name
usercontrol2 and also UserControl1 should not visible to do so write on
button click event of UserControl1
UserControl2 second = new UserControl2();
this.Hide();//because usercontrols
have not Close() property as forms
this.Parent.Controls.Add(second);