Link to home
Start Free TrialLog in
Avatar of dr_dudd
dr_dudd

asked on

Creating tooltips

Below is the code i am using to create labels on runtime, my question is how can i add tooltips to these labels?


Dim sectortime As DateTime
Dim sectors(250) As Label
Dim sectip As ToolTip
Dim seclength As Integer
Dim secposition As Integer
Dim sectorto As String


With sectors(currentlabelnumber)
                                .Left = secposition + seclength - 5
                                .Top = 131 + (k * 182 - 150 + value)
                                .Text = sectorto
                                .AutoSize = True
                                .BorderStyle = BorderStyle.FixedSingle
                            End With
                            Me.Controls.Add(sectors(currentlabelnumber))
                           
 sectip.SetToolTip(Me.sectors(currentlabelnumber), sectortime)

                            currentlabelnumber = currentlabelnumber + 1

As you can see i have tried adding a tooltip, but on runtime i am informed that object refrence not set to an instance of an object.

Any help is much appreciated.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Hi dr_dudd,

You need to add a ToolTip component to your form and call ToolTip1.SetToolTip(YourControlName, "Your tip")

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dr_dudd
dr_dudd

ASKER

Hi emoreau

I have already tried this.... if you look closely at the code in the question you will already see the lines...

Dim sectip As ToolTip

sectip.SetToolTip(Me.sectors(currentlabelnumber), sectortime)
Try:

                sectip= New ToolTip
                sectip.SetToolTip(Me.sectors(currentlabelnumber), sectortime.ToString)
                sectip.Active = True
dr_dudd,

but I don't think that your Tooltip as you defined it belongs to the form so the form cannot show it! Try adding a Tooltip component and use that one.