Show ToolTip on every Control continuously

  • Thread starter Thread starter Pieter
  • Start date Start date
P

Pieter

Hi,

Using VB.NET 2.0, Windows Forms.
I want the ToolTip to be shown on every TextBox, ComboBox and DataGridView
continuously, and show the contence of these controls. Is there a way to add
the ToolTip automaticly for all these controls, without having to link it
the whole time to them for every new Control I put on my Forms?

And regarding the DataGridView: The ToolTip doesn't show the whole value of
every Cell, but cuts it off when it's too long. how to get around this?

Thansk a lot in advance,

Pieter
 
Hi Pieter,

For automatically initializing all tooltip for all the components on
your form try calling this procedure from the Form1_load event:

Private Sub SetToolTips()
Dim i As Control
For Each i In Me.Controls
ToolTip1.SetToolTip(i,
i.ToString.Substring(i.ToString.IndexOf("Text:") + 5))
Next
End Sub

If you test this with the caption just "i.tostring", you'll see why I
parsed the control.tostring in this way.

I'm not sure if there is a less intensive way to automatically update
the tooltip text in the event of a change without writing an individual
event handler for each control.

Regarding the DataGridView cells question, I'm not sure what you mean.
What are you trying to do, and what does the application show? Are you
building the Tooltip caption?

Regards,
Keith
 
I don't think what you want to do is possible. The Tooltip window is usually
a single instance of a simple window that shows a string which it gets by
looking at a record in a hashtable which is associated with a control. To
show a whole lot of windows from this one object and to show more than one
string at a time is pretty well impossible.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
This would work well unless the control is belong to a secondary
container like Panel or GroupBox. I guess that you don't want to show
tooltip for every control (like Panel, etc.) so you may need some "if"s
inside. Something like the following would do the job:

Private Sub SetToolTips(ByVal ctrl as Control)
{
if typeof ctrl is Form OrElse typeof ctrl is Panel OrElse ... then
' do nothing
else if typeof ctrl is DataGridView/listview/treeview then
' do something as per requirements
else ' other control, just set text
toolTip1.SetToolTip(ctrl, ctrl.Text);
end if

for each child as Control in ctrl.Controls
SetToolTips(child) ' recursive
next
}

Then, in constructor or form load, you could call SetToolTips(Me).

Thi
 
Back
Top