Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Please help me to show tooltip for all buttons on one click.
For single button tooltip i have used:

CSS
buttonToolTip.UseFading = false;
buttonToolTip.UseAnimation = false;
buttonToolTip.IsBalloon = false;
buttonToolTip.ShowAlways = true;
buttonToolTip.AutoPopDelay = 5000;
buttonToolTip.InitialDelay = 1000;
buttonToolTip.ReshowDelay = 0;

buttonToolTip.SetToolTip(button1,"Hello");


How to do it for all buttons at once?
Posted
Updated 27-Jan-15 1:54am
v3

A WinForm 'ToolTip is an "extender provider" Control: you'll notice that when you drag-drop one onto a Form its icon appears below the Form in the area where Components also show-up.

At design-time:

Once you add a ToolTip to your project then you'll find that when you open the Property Browser for any Control it will have a field where you can enter Text with a name like: ToolTip on toolTip1.

1. you can select (using the mouse) any number of Controls on a Form, of any Type, open the Property browser and set the selected Controls' ToolTip static text: that text will appear when the mouse is hovered over any of the Controls you selected.

At run-time:

1. initialzing ToolTip content when the Form loads:
C#
private void Form1_Load(object sender, EventArgs e)
{
    foreach (Button btn in this.Controls.OfType<Button>())
    {
        toolTip1.SetToolTip(btn, btn.Name);
    }
}
Keep in mind that this would find all the Button on the Form surface and set their ToolTips to the Button's 'Name property; it would not find any Button inside a container Control, like a Panel (in other words, it is not a recursive function).

2. if you wish different dynamic content presented by the Tooltip depending on the Control the ToolTip is activated for:

a. usually you will have some EventHandler installed for a Control, or Controls, and in that EventHandler you will make the call the shows the ToolTip with the text you want.

b. So, say you had six Buttons on a Form, and you wired-up a MouseHover EventHandler for all six Buttons like this:
C#
Point btnOffset = new Point(75,0);

private void SixButtons_MouseHover(object sender, EventArgs e)
{
    Button hoverButton = sender as Button;

    toolTip1.Show(hoverButton.Name, hoverButton, btnOffset);
}
In this case the variable 'btnOffset of Type 'Point controls where you want the 'toolTip1 to be shown relative to the upper-left corner of the Button the mouse hovers over.

Example b. is a bit "silly," because: why would want to use some kind of dynamic code to show a property that doesn't change (is static).

There are rare occasions where you may want to give different ToolTip feedback based on what the user of your application is doing, and that's when you might go to the trouble of implementing dynamic ToolTip content.
 
Share this answer
 
If I have right understood you, you need a loop through ALL buttons of your Page/Form:

C#
foreach(Control c in Page.Controls)
{
    Button b = c as Button;
    if(b!=null)
    {
       //do stuff
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900