Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
How to get the height of a tooltip control?

 

You may be able to modify the following code to measure the height of a tooltip.

 

public static void AutoSizeLabelHeight(Label ctlLabel)
{
Graphics g = ctlLabel.CreateGraphics();
Font font = new Font(ctlLabel.Font.Name, ctlLabel.Font.Size, ctlLabel.Font.Style);

StringFormat sf = new StringFormat();

SizeF stringSize = g.MeasureString(ctlLabel.Text, font, ctlLabel.Width, sf);

ctlLabel.Height = (int) stringSize.Height + 2;

g.Dispose();
font.Dispose();
sf.Dispose();
}

Posted
Not really, since the tooltip doesn't have a font. I suppose I can just create a label and assume it has the same font as a tooltip, but it's a bit of an assumption.
  • Leaders
Posted
You can get the font used for ToolTip. It might be in the SystemInformation class. If not, it should be get-able from the Windows API. That is still an iffy way to find a ToolTip size. Why, if you don't mind my asking, are you looking to find the size of a ToolTip?
[sIGPIC]e[/sIGPIC]
Posted
You can get the font used for ToolTip. It might be in the SystemInformation class. If not' date=' it should be get-able from the Windows API. That is still an iffy way to find a ToolTip size. Why, if you don't mind my asking, are you looking to find the size of a ToolTip?[/quote']

Can't find it in the SystemInformation class. I want it because I'm using it as an autotext hint (like in Word) and want to be able to position it properly above the point where the user is typing. I think just using the value that I find on my system should be OK, though.

Posted
Would it be unacceptable to display the hint below the text?

 

Yes is the short answer. I'd rather that it was unreliably positioned above, than accurately positioned below.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...