473,386 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I create a tooltip programatically for a programaticallygenerated label

Hi

I have code to programatically create a label. It works but when I try
to call a sub to create a tooltip it does not work. I do not get an
error so have no idea what it wrong. Please review my code and tell me
how to fix it.

Thanks

The Mad Ape
www.tatumba.com

CODE TO CREATE LABEL:

Dim tabLblPulp As New Label
tabLblPulp.Location = New Point(14, 121)
tabLblPulp.Size = New Size(54, 13)
tabLblPulp.Name = tp.Text & "lblPulpwood"
tabLblPulp.Text = "Pulpwood"
tabLblPulp.ForeColor = Color.Blue
tabLblPulp.Visible = True
tabLblPulp.Font = New System.Drawing.Font("Microsoft
Sans Serif", 8.25!, System.Drawing.FontStyle.Underline,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
tp.Controls.Add(tabLblPulp)

'code to call sub

AddHandler tabLblPulp.Click, AddressOf ToolTiper

Public Sub ToolTiper(ByVal sender As Object, ByVal e As EventArgs)

Dim ctrlName As String
ctrlName = DirectCast(sender, Control).Name()
Dim ToolTip2 As New ToolTip
Dim ctrl As Control
For Each ctrl In Form7.Controls
If ctrl.Name = ctrlName Then
ToolTip2.SetToolTip(ctrl, "Test")
End If
Next

End Sub
Apr 6 '08 #1
7 6723
The Mad Ape wrote:
Hi

I have code to programatically create a label. It works but when I try
to call a sub to create a tooltip it does not work. I do not get an
error so have no idea what it wrong. Please review my code and tell me
how to fix it.
What's wrong: Form7.Controls will contain only the controls that are directly on
the form, such as a tab control. The tab control itself will contain the tab
pages; one tab page will in turn contain controls that are on it, such as a
label. So your hunt through Form7.Controls never finds the control in question.

How to fix it: You have a DirectCast to Control, using the sender of your event.
Guess what? That's the control you want. There is no need to get its name, then
go try and find it in a control collection somewhere. You already have it.

Just do
ctrl = DirectCast(sender, ctrl)
ToolTip2.SetToolTip(ctrl, "Test")
Apr 7 '08 #2
On Apr 6, 9:12 pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
The Mad Ape wrote:
Hi
I have code to programatically create a label. It works but when I try
to call a sub to create a tooltip it does not work. I do not get an
error so have no idea what it wrong. Please review my code and tell me
how to fix it.

What's wrong: Form7.Controls will contain only the controls that are directly on
the form, such as a tab control. The tab control itself will contain the tab
pages; one tab page will in turn contain controls that are on it, such as a
label. So your hunt through Form7.Controls never finds the control in question.

How to fix it: You have a DirectCast to Control, using the sender of your event.
Guess what? That's the control you want. There is no need to get its name, then
go try and find it in a control collection somewhere. You already have it.

Just do
ctrl = DirectCast(sender, ctrl)
ToolTip2.SetToolTip(ctrl, "Test")
Hi

I tried the following:

Public Sub ToolTiper(ByVal sender As Object, ByVal e As EventArgs)

Dim ToolTip2 As New ToolTip
Dim ctrl As Control
ctrl = DirectCast(sender, Control)
ToolTip2.SetToolTip(ctrl, "Test")

End Sub

Still nothing. No error but no tool tip either. I am totally confused
now. I am using VB.Net from VS 2005 SP2. Any ideas? This control does
reside on a tabpage if that means anything.

I would appreciate any help you could provide.

Thanks

Apr 7 '08 #3
On Sun, 6 Apr 2008 17:34:44 -0700 (PDT), The Mad Ape
<ch******@gmail.comwrote:
>On Apr 6, 9:12 pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
>The Mad Ape wrote:
Hi
I have code to programatically create a label. It works but when I try
to call a sub to create a tooltip it does not work. I do not get an
error so have no idea what it wrong. Please review my code and tell me
how to fix it.

What's wrong: Form7.Controls will contain only the controls that are directly on
the form, such as a tab control. The tab control itself will contain the tab
pages; one tab page will in turn contain controls that are on it, such as a
label. So your hunt through Form7.Controls never finds the control in question.

How to fix it: You have a DirectCast to Control, using the sender of your event.
Guess what? That's the control you want. There is no need to get its name, then
go try and find it in a control collection somewhere. You already have it.

Just do
ctrl = DirectCast(sender, ctrl)
ToolTip2.SetToolTip(ctrl, "Test")

Hi

I tried the following:

Public Sub ToolTiper(ByVal sender As Object, ByVal e As EventArgs)

Dim ToolTip2 As New ToolTip
Dim ctrl As Control
ctrl = DirectCast(sender, Control)
ToolTip2.SetToolTip(ctrl, "Test")

End Sub

Still nothing. No error but no tool tip either. I am totally confused
now. I am using VB.Net from VS 2005 SP2. Any ideas? This control does
reside on a tabpage if that means anything.

I would appreciate any help you could provide.

Thanks
Your code works for me. Is ToolTiper() being called?
Apr 7 '08 #4
The Mad Ape wrote:
I am creating the label and using Add Handler. Doesn't the Add Handler
statement call ToolTiper?
AddHandler tabLblPulp.Click, AddressOf ToolTiper
No, it just sets it up to handle tabLblPulp.Click events. It would get called
when you click on the label.

Based on your misunderstanding, you probably don't want or need the code in the
label click event. That would mean it didn't have a tooltip at first; if you
click it, then it will have one after.

You may just want to put those lines after you have finished making the label:
' ....
tp.Controls.Add(tabLblPulp)

' now just add the tooltip to it

Dim ToolTip2 As New ToolTip
ToolTip2.SetToolTip(tabLblPulp, "Test")

The tooltip object itself handles the display of the tooltip when the user
hovers over the label a certain amount of time, and all the other behavior of
it.
Apr 8 '08 #5
On Apr 7, 11:14 pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
The Mad Ape wrote:
I am creating the label and using Add Handler. Doesn't the Add Handler
statement call ToolTiper?
AddHandler tabLblPulp.Click, AddressOf ToolTiper

No, it just sets it up to handle tabLblPulp.Click events. It would get called
when you click on the label.

Based on your misunderstanding, you probably don't want or need the code in the
label click event. That would mean it didn't have a tooltip at first; if you
click it, then it will have one after.

You may just want to put those lines after you have finished making the label:
' ....
tp.Controls.Add(tabLblPulp)

' now just add the tooltip to it

Dim ToolTip2 As New ToolTip
ToolTip2.SetToolTip(tabLblPulp, "Test")

The tooltip object itself handles the display of the tooltip when the user
hovers over the label a certain amount of time, and all the other behavior of
it.
When I first wrote this code, this is what I did. And when it did not
work I branched out into the sub and handler. I tried it again and it
still does not work. So in an effort to find out what is going on I
added a label to the tab and referenced it in the tool tip code that
you suggested. It works so the problem lies in the wiring between the
code used to create the label and the code to create the tool tip.

Next I wrote the code to add a new label to the form and it works. So
the problem appears to be when I attempt to add the tooltip to a
control on a tab.

Would this be a, as yet, undiscovered bug in VB.net or is there a
missing step because of the tab?

Thanks
Apr 8 '08 #6
I re-read my last response and I think I need to be more clear as to
what is going on.

1) I can programatically create a label and programatically add a tool
tip to that label when the label is on a form.
2) I can programatically create a tool tip for an already existing
label on a tab page
3) I can programatically create a label on a tab page but the same
code used in #1 to programatically create a tool tip does not work and
I don't know why.
Apr 8 '08 #7
On Apr 8, 8:07 am, The Mad Ape <chief...@gmail.comwrote:
I re-read my last response and I think I need to be more clear as to
what is going on.

1) I can programatically create a label and programatically add a tool
tip to that label when the label is on a form.
2) I can programatically create a tool tip for an already existing
label on a tab page
3) I can programatically create a label on a tab page but the same
code used in #1 to programatically create a tool tip does not work and
I don't know why.
Finally after 3 days I have found the problem. Prior to creating the
label and tooltip I had code to create a rectangle and some lines
using Visual Basic Power Pack 3.0. If you draw the lines first they
hide the tool tip and cursor settings. If you add the lines after the
tooltip and cursor have been added then it will work. Sort of works in
reverse logic.

I thank you guys for helping through this very frustrating experience.
Now I can go forward with this project.

The Mad Ape
www.tatumba.com
Apr 8 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stephen | last post by:
Is it possible to add a tooltip in the column of a Datagrid. Can someone please show me how I would do this for the datagrid column below. Thanks for any help anyone can give me. Here is the...
6
by: Robert | last post by:
Hello. I have been trying out the Lebans ToolTip Classes at http://www.lebans.com/tooltip.htm, to display "balloon" style help tips in a form. The classes I am using are located at...
0
by: Sam Sungshik Kong | last post by:
Hello! I have a form with a button, a label, a toolTip and a notifyIcon. I set the "ToolTip on toolTip1" of the label. For the button click: private void button1_Click(object sender,...
4
by: Henry Padilla | last post by:
I am making a UserControl that is entirely taken up by Labels. I have found a way to pass the Click even to the outside (I have the same handler for each label.click and that raises a...
8
by: Rachel Suddeth | last post by:
I have an application where some forms have many (say 100) UserControls on them (each of which contain a label, an image, and a data entry control), and each UserControl has a ToolTip provider...
7
by: | last post by:
Is there a way to change the "fadeout" of a tooltip? In other words, it'll display for about 10 seconds which may or may not be long enough for a user to read the tooltip. I'd like to...
3
by: Craig G | last post by:
what way do you code it? i tried the following but it wouldnt display it lblAdd_info is a hidden field in the cell itself that contains the data i want to display in the tooltip text. i added the...
4
by: rn5a | last post by:
A DataList displays 3 columns - Product, Category & Price. These columns are populated with records from a SQL Server 2005 DB table. Apart from the above 3 DB columns that the resultset retrieves,...
1
by: Alex | last post by:
Hi all - I'm trying to put a tooltip on a label in csharp... I found an example that says to add some code to the InitializeComponent() method, but that's in the .Designer.cs file - which says...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.