How to pop up a tooltip at a specific position
I am trying to integrate a toolwindow in a Winforms application, it will be a tiny floating window to display the details of an item in a list. What I need is to put the window in a relative position to the control that launches the action, so here's what: the Location property gives me the relative position of the control from its container (main form in this case), so this is im workaround using :
public void Show(kTextBox source)
{
Point absCoord = source.PointToScreen(source.Location);
this.Location = this.PointToClient(absCoord);
base.Show();
}
Basically it is: get the absolute position of the control and set that position (previously converted to relative owner) to the tool window. I think it should work fine, but is missing to a certain extent and it depends on which control I am using. This confuses. Was there anyone? Thanks in advance.
+2
a source to share
2 answers
private void button1_Click(object sender, EventArgs e)
{
ToolStripDropDown popup = new ToolStripDropDown();
popup.Margin = Padding.Empty;
popup.Padding = Padding.Empty;
ToolStripControlHost host = new ToolStripControlHost(frm);
host.Margin = Padding.Empty;
host.Padding = Padding.Empty;
popup.Items.Add(host);
popup.Show(button1, button1.Left - 10, button1.Top + (int)(button1.Height / 2));
}
Form2 frm = new Form2();
private void Form1_Load(object sender, EventArgs e)
{
frm.TopLevel = false;
}
}
-1
a source to share