Need to load usercontrols to my form dynamically. I have menu and passing name of usercontrols when choosing menu items.
private void MenuItemClickHandler(object sender, EventArgs e)
{
ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
MessageBox.Show(clickedItem.Name);
}
How can load user control in this event? In Asp.Net for such cases i’ve used LoadControl(“path/name.ascx”). I didn’t find analog in winforms.
If you have the name of the control, and the controls are already compiled into your application, you can use
Activator.CreateInstanceto create an instance of the control from the type name. Once you create an instance of the control, you can add it to your form. Something like the code below should work: