Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard - 27 Sep 2007 17:38 GMT
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 ?
Dave Anson - 27 Sep 2007 21:25 GMT
> 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;
}
Richard - 28 Sep 2007 17:38 GMT
> > A rather longish bit of text, may a really long
> > pathname or something similar
[quoted text clipped - 5 lines]
>
> }

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.