I am trying to use UserControl in panel of windows form. But it is not being showed.
Method of the form:
public void SetContent(UserControl control) {
contentPanel.Controls.Clear();
control.Dock = DockStyle.Fill;
contentPanel.Controls.Add(control);
control.Show();
contentPanel.Show();
control.Refresh();
contentPanel.Refresh();
Refresh();
}
Initialization
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyForm form;
Application.Run(form=new MyForm());
form.SetContent(new MyControl());
}
CodePudding user response:
If you want to use UserControl in panel of windows form, you can refer to the following code:
private void Form1_Load(object sender, EventArgs e)
{
var myControl = new UserControl1();
contentPanel.Controls.Add(myControl);
}