Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

If you only have 1 tool tip and you have a control collection which is in the same order as your array of strings in other words:

 

Control1 Tool Tip = name(0)

Control2 Tool Tip = name(1)

Control3 Tool Tip = name(2)

 

And you have all the controls in a collection you would:

 

For i as Integer = 0 to MyCollection.Count - 1

MyToolTip.SetToolTip(MyCollection(i), name(i))

Next

 

I wouldn't say this is good practice because your tightly couple the control length and order to names array length and order.

  • *Experts*
Posted

I think it'll be easier to interate through your form's controls, comparing names and setting the tool tip from the control name value.

 

I am assuming that you have a 2D array with control name and tooltip fields like:

myCollection(0, 0) = "txtName"

myCollection(0, 1) = "Please enter your name"

myCollection(1, 0) = "txtAddress"

myCollection(1, 1) = "Please enter your mailing address"

etc.

 

Dim ctrl as Control
Dim i as Integer
For i = 0 to myCollection.GetUpperBound(0)
   For Each ctrl in Me.Controls
       If ctrl.Name = myCollection(i, 0) Then
           ToolTip1.SetToolTip(ctrl, (i, 1))
            Exit For
       End If
   Next
Next

 

I haven't tested this but I think it should work fine.

 

Also, if you have any controls that require tool tips in other "container" controls like Panels or GroupBoxes then you'll need to iterate through them separately.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

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...