Why does the ToolTip not appear when set to a long string?
I am working in VB.Net 2010 framework 2.0. I am setting a big string to tooltip object. In this case tooltip is not appearing. If the string is shor开发者_开发知识库t (say of 10 lines), tooptip is appearing properly.
The following is the code:
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
If _showToolTip Then
If Not IsNothing(_tooltipDSPanel) Then
_tooltipDSPanel.Dispose()
_tooltipDSPanel = Nothing
End If
_tooltipDSPanel = New ToolTip
_tooltipDSPanel.SetToolTip(Me, PanelText)
End If
End Sub
If the "PanelText" is too long (say 50 lines), it does not appear. Sometimes it shows an empty tooltip.
Where I am going wrong?
Thanks for any reply in advance.
ToolTip.SetToolTip uses the TTM_SETTOOLINFO message to update the tool tip. The SDK docs for this message contain this phrase:
When calling TTM_SETTOOLINFO, the string pointed to by the lpszText member of the TOOLINFO structure must not exceed 80 TCHARs in length, including the terminating NULL.
Which is an expensive way of saying that the updated tip text cannot be longer than 80 characters. This limit has been expanded in later versions of Windows, you didn't say which one you are using.
In general, you really want to avoid displaying lots of text in a tip. It isn't visible long enough to allow the user to read the novella. Consider implementing F1 help as an alternative.
The tooltip wasn't designed for large amounts of text. Its performance degrades quickly as the character number increases. It's really only usable up to about 1000 characters in my experience. Anything over this takes several seconds to appear. As such, it may be disappearing before it actually renders. I would try setting the AutoPopDelay to a high number to see if it shows at all.
For one thing there's some weird stuff going to happen because when the tooltip pops you will have a mouse leave event then when the tooltip goes you will have another mouse enter event which kills the tooltip and starts a new one.
I would usually just do this:
If _showToolTip Then
_tooltipDSPanel.SetToolTip(Me, PanelText)
End If
You just need the one tooltip, just give it different text when you need to. And you can let the form worry about disposing it when it's done with it.
精彩评论