Hi,
I want to add a control to a user control in an event handler (like a button click event).
I'm trying to add a datagridview lookup control dynamically, but I couldn't get that to work, so I tried just adding a button with this code:
private void btnCreateNewButton_Click(object sender, EventArgs e)
{
Button btn = new Button();
btn.Location = new Point(100, 640);
btn.Size = new Size(100, 30);
btn.Text = "Click Me";
btn.Click += (s, ea) => MessageBox.Show("New button clicked");
this.Controls.Add(btn);
}
When i click my Create New Button, no button appears.
If I add the exact same code into a form instead of a usercontrol, the button is created and displays as intended, but in a user control nothing happens. In the user control I've also tried
this.Parent.Controls.Add(btn) and
this.ParentForm.Controls.Add(btn)
but to no avail.
Anybody got any ideas?
Thanks, Ciaran.