Make a TextBox tooltip appear in-place (same as overly wide TreeView node texts)


R

Richard

I'm trying to mimic how the TreeView shows a full text inplace tooltip
when the mouse hovers over of TreeView node whose text is truncated
due to skinny form or panel.


In the IDE I have
Text1.text is 'A rather longish bit of text, may a really long
pathname or something similar';
ToolTip1.OwnerDraw is True (this causes ToolTip1_Draw() to run)

I was hoping this would work...

private void toolTip1_Draw(object sender, DrawToolTipEventArgs
e)
{
ToolTip1.Show(e.ToolTipText, e.AssociatedWindow,
0,0,5000);
}

But it throws Win32Exception .. Error creating window handle.

Can anyone recommend some quick and dirty code for doing inplace
tooltips ?
 
Ad

Advertisements

D

Dave Anson

A rather longish bit of text, may a really long
pathname or something similar



private void textBox1_MouseHover(object sender, System.EventArgs e)
{
this.toolTip1.SetToolTip( ((TextBox)sender), ((TextBox)sender).Text );
this.toolTip1.Active = true;
}
 
Ad

Advertisements

R

Richard

private void textBox1_MouseHover(object sender, System.EventArgs e)
{
this.toolTip1.SetToolTip( ((TextBox)sender), ((TextBox)sender).Text );
this.toolTip1.Active = true;

}

Thanks Dave,

I ended up with this little more complicated mousehover handler. The
'in-place' part is ensuring the tool tip overlays the text field very
closely (things can be minorly different if different fonts for
tooltip and textbox)

TextBox t = (TextBox)sender;
Point p = this.PointToClient(t.PointToScreen(t.Location));
p.X = p.X + SystemInformation.BorderSize.Width *
SystemInformation.BorderMultiplierFactor - 1;
p.Y = p.Y + SystemInformation.BorderSize.Height *
SystemInformation.BorderMultiplierFactor + 1;
toolTip1.Show(t.Text, this, p, 5000);

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top