Ok wasted enough time on this :) add new line in tooltip during IDE

i remember vb6 had this, i just can remember the key to make my description do a new line!


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ahem, do you mean i.e.

Cheers & HTH,
Shiju SasidharanSenior IT DeveloperCommented:

'Place a tooltip control and a button on ur form and try this

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolTip1.SetToolTip(Button1, "First Line" & vbCrLf & "Second Line")
 End Sub
5thcavAuthor Commented:
nope ide at development, not in code,, was it &;
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Shiju SasidharanSenior IT DeveloperCommented:
u mean
he doesn't mean "how do i add a new line to a string in code?" ... he means in VS.NET, at design-time.

i'd love to know howto do this too, if someone finds out how.  you can always go into the windows designer code and add your line breaks, but the designer has a tendency to null out the whole string when it sees you've done that ... because it's mean.

like ...

how can i add a label to a form at design time and add line breaks to its text?

i always work-around this pretty easily by setting the .Text on form_load, but it would be nice to be able to add text with linebreaks to a label/textbox/tooltip/whatever at design time, with VS.NET.

can it be done?
5thcavAuthor Commented:
i hope so,,, i thought vb6 done this,,, i guess i can do it on code,,, i only have to do it for 10 items,,, im trying to make the program as easy as possible
to cut down on phone calls,, :)
the ampersand works ,, why the hell the & adds  a hot key to the ToolTip id like to know that too!!!,, and if it has the function to add the & amp _ then im betting it has the function to make a new line
After some research, my conclusion is that there's no easy way to do it at design time. I think the only way to get around this is to customize the ToolTip. But I would rather get the same result by writing code at runtime, like the code shijusn has provided.
5thcavAuthor Commented:
It seems strange doesn’t it, That the ampersand works in the tool tip and there is no CR feature?
5thcavAuthor Commented:
do you remember what the VB6 code was? it must still be there,,,, im having a hard time to finding the information,,,,Kind of a weird search
5thcavAuthor Commented:
found this but i cant get in working/converted

private extern static int SendMessage(IntPtr hwnd,uint msg, int wParam, int lParam);
object o = typeof(ToolTip).InvokeMember("Handle",BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetProperty,null,myToolTip,null);
IntPtr hwnd = (IntPtr) o;
SendMessage(hwnd,0x0418, 0, 300);
5thcavAuthor Commented:
this works nice

Friend Function SplitToolTip(ByVal strOrig As String) As String
        Dim strArray As String()
        Dim SPACE As String = " "
        Dim CR As String = vbCrLf
        Dim strOneWord As String
        Dim strBuilder As String
        Dim strReturn As String
        strArray = strOrig.Split(SPACE)
        For Each strOneWord In strArray
            strBuilder = strBuilder & strOneWord & SPACE
            If Len(strBuilder) > 70 Then
                strReturn = strReturn & strBuilder & CR
                strBuilder = ""
            End If
        If Len(strBuilder) < 8 Then strReturn = strReturn.Substring(0, _
                                                    strReturn.Length - 2)
        Return strReturn & strBuilder
    End Function

           Dim tt As String = ToolTip1.GetToolTip(lblLColor1)
        If Not tt = Nothing Then
            If tt.Length > 75 Then ToolTip1.SetToolTip(lblLColor1, SplitToolTip(tt))
        End If
Fernando SotoRetiredCommented:
Hi  5thcav;

This can not be done at design without adding some code. The following code was found at the following web sites

Must be a member to get to this web site.

Function GetChildControls(ByVal ctrl As Control) As Control() found on this web site

In the main form place the following two function.

    ' this code assumes the following Imports statements
    '      Imports System.Collections
    '      Imports System.Windows.Forms
    ' return all the controls in a control container
    ' (including controls inside other controls)
    Function GetChildControls(ByVal ctrl As Control) As Control()
        Dim controls As New ArrayList
        For Each c As Control In ctrl.Controls
            ' add this control and all its nested controls
        ' return the result as an array of Controls
        Return DirectCast(controls.ToArray(GetType(Control)), Control())
    End Function

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        If Me.DesignMode Then Exit Sub

        For Each ctrl As Control In GetChildControls(Me)
            Dim tooltip As String = _
            If Not tooltip Is Nothing Then
                ToolTip1.SetToolTip(ctrl, _
            End If
            Dim helpString As String = _
            If Not helpString Is Nothing Then
                HelpProvider1.SetHelpString(ctrl, _
            End If
    End Sub

In the code "Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)" also does the same for the HelpProvider
control which has the same problem. Comment out the bottom half if you do not have a HelpProvider.
Then at design time you can use \n for new line and \t for a tab.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
5thcavAuthor Commented:
Hi FernandoSoto,,

what is Regex
Fernando SotoRetiredCommented:
It is the Regular Expression Class. You need to add "Imports System.Text.RegularExpressions". Here is a link to the doc page.


5thcavAuthor Commented:
wow thats what i needed,,  i was finding sites that said to add \n but nothing was working,, i must have been 100 pixles away from that answer,, lol

thats for the help
Fernando SotoRetiredCommented:
No problem I am glad I was able to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.