Reputation: 533
I have created a UserControl and I want when I click on some button to display this UserControl into my form.
Is there any way to do that ?
Upvotes: 3
Views: 32816
Reputation: 795
Is it a typical ascx type of control? If yes then you can set the "visible" property of the control through the button click event.
Let say you have :
<uc1:ft ID="userctrl" runat="server" Visible="false" />
then on your button event:
protected void Button1_Click(object sender, EventArgs e)
{
userctrl.Visible = true;
}
Upvotes: 0
Reputation: 14243
You can dynamically add the user control to the forms Controls collection.
For example, in the button click event handler:
MyUserControl uc = new MyUserControl();
uc.Dock = DockStyle.Fill;
this.Controls.Add(uc);
Upvotes: 11
Reputation: 2168
Drag your user control to your form and change it's Visible property to false
UserControl1.Visible = false;
Then on your button set the Visibility of your usercontrol to true.
private void button1_Click(object sender, EventArgs e)
{
UserControl1.Visible = true;
}
Upvotes: 0
Reputation: 20640
Put it on the form. Start it out invisible, when the button is clicked set it to visible.
Upvotes: 0