一次为所有按钮设置工具提示 [英] Set Tooltip for all buttons at once

查看:65
本文介绍了一次为所有按钮设置工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请帮我一键显示所有按钮的工具提示。

对于我使用过的单键工具提示:



  buttonToolTip  UseFading   =  false; 
buttonToolTip UseAnimation = 假;
buttonToolTip IsBalloon = 假;
buttonToolTip ShowAlways = 真正;
buttonToolTip AutoPopDelay = 5000;
buttonToolTip InitialDelay = 1000;
buttonToolTip ReshowDelay = 0;

buttonToolTip .SetToolTip(button1,Hello);





如何一次为所有按钮执行此操作?

解决方案

一个WinForm'工具提示是一个扩展程序提供者控件:你会注意到当您将一个拖放到表单上时,其图标将显示在组件也显示的区域中的表单下方。



在设计时:



一旦你将一个工具提示添加到你的项目中,你就会发现当你为任何一个Control打开属性浏览器时它会有一个你可以使用的字段输入名称为:ToolTip on toolTip1的文本。



1.您可以选择(使用鼠标)任何类型的表格上的任意数量的控件,打开属性浏览器并设置所选控件的工具提示静态文本:当鼠标悬停在您选择的任何控件上时,将显示该文本。



At运行时间:

  private   void  Form1_Load( object  sender,EventArgs e)
{
foreach (按钮btn in this .Controls.OfType< Button>())
{
toolTip1.SetToolTip(btn,btn.Name);
}
}

请记住,这会找到Form表面上的所有Button,并将其工具提示设置为Button的'Name属性;它不会在容器Control中找到任何Button,就像Panel一样(换句话说,它不是一个递归函数)。



2.如果你想要不同的动态工具提示所显示的内容取决于控件工具提示被激活:



a。通常你会为Control或者控件安装一些EventHandler,在那个EventHandler中,你将调用带有你想要的文本的工具提示。



b 。所以,假设你在表单上有六个按钮,并且你为所有六个按钮连接一个MouseHover EventHandler,如下所示:

 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);
}

在这种情况下,变量'BtnOffset of Type'Point控制你想要'toolTip1相对于鼠标悬停在Button上的左上角显示的位置。 />


例b。有点愚蠢,因为:为什么要使用某种动态代码来显示一个不会改变的属性(是静态的)。



那里在极少数情况下,您可能希望根据应用程序的用户所做的事情提供不同的工具提示反馈,这时您可能会遇到实现动态工具提示内容的麻烦。


如果我理解你了,你需要循环浏览你的页面/表格的所有按钮:



  foreach (控制c  Page.Controls中)
{
按钮b = c as 按钮;
if (b!= null
{
// 做东西
}
}


Hi,

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

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?

解决方案

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:

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:

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.


If I have right understood you, you need a loop through ALL buttons of your Page/Form:

foreach(Control c in Page.Controls)
{
    Button b = c as Button;
    if(b!=null)
    {
       //do stuff
    }
}


这篇关于一次为所有按钮设置工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆