How to limit the width of ToolTip control?

  • Thread starter Thread starter YXQ
  • Start date Start date
Y

YXQ

Extract the string from XML file, using ToolTip1.SetToolTip to load the
string, but the width is big, how to limit the width of ToolTip? thank you.
 
Extract the string from XML file, using ToolTip1.SetToolTip to load the
string, but the width is big, how to limit the width of ToolTip? thank you.

How long Tooltip shows a text depends how long the text is. As Jan
pointed out, you need to limit the text by trimming or removing
specified range or use substring to set specified part of text.

Additionaly, tooltip's text is splitted into lines automatically when
the text is longer than your screen resolution's width, if your
concern was about aligning the long text of tooltip.

Hope this helps,

Onur Güzel
 
The following code fragment shows one way of doing this:

Dim Original As String = "This is the very long tooltip text that needs to
be reformatted to multiple lines of narrower width in order to create a
suitably shaped tooltip text block."
Dim Narrowed As String = ""
Dim A() As String = Split(Original)
Dim temp As String = ""
Dim M As Integer = 42 'Maximum width
For Each S As String In A
If temp.Length + S.Length >= M Then
Narrowed += temp & vbCrLf
temp = LTrim(S)
Else
temp += " " & S
End If
Next
Narrowed = LTrim(Narrowed) & temp
ToolTip1.SetToolTip(<insert control name here>, Narrowed)
 
Back
Top