I am trying to programmatically set a tooltip for a label (added at runtime) in a UserControl on a form. The button used to run the code is located in the user control itself. The problem is that when I click the button, a tooltip is not assigned. However, if I use basically the same code in the parent form and put it behind the button in the parent form, I can assign a tooltip to the shortcut in the parent form. Also, if I add a shortcut to the user control before launching, it also works.
The following code is from a button on a user control that is in the main form.
private void button1_Click(object sender, EventArgs e)
{
Label lblTest = new Label();
lblTest.Text = "Test";
ToolTip tt = new ToolTip();
tt.SetToolTip(lblTest, "ToolTipTest");
this.Controls.Add(lblTest);
lblTest.Location = new Point(10, 10);
}
Any help would be greatly appreciated.
source