vb.net HowTo 动态工具提示或一键更改工具提示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17954051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HowTo Dynamic ToolTip or changing tooltip on one button
提问by Jeremy
I have a small VB winforms app with a forward and back button. These two buttons allow you to cycle through numerous "pages". I would like to display the next and previous page title in tooltips when the mouse hovers over the buttons(arrows).
我有一个带有前进和后退按钮的小型 VB winforms 应用程序。这两个按钮允许您循环浏览多个“页面”。当鼠标悬停在按钮(箭头)上时,我想在工具提示中显示下一页和上一页标题。
Example, when hovering over the left arrow button, I would like to display the name previous page. So page 1 is applications, page 2 is emails, page 3 is pdf documents etc...
例如,当鼠标悬停在左箭头按钮上时,我想显示上一页的名称。所以第 1 页是应用程序,第 2 页是电子邮件,第 3 页是 pdf 文档等等......
I added the tooltip property from the toolbox in Visual Studios, but it only allows me to type a single item as opposed to scrolling through my list of pages and determining what the previous page name is and displaying it.
我从 Visual Studios 的工具箱中添加了 tooltip 属性,但它只允许我键入单个项目,而不是滚动浏览我的页面列表并确定上一个页面名称是什么并显示它。
The page or form itselt doesn't change, and neither do the buttons, just a panel contained inside the form has the "pages" that change, so I need to be able to write a function that figures out which page is previous and which page is next on the fly when mousehovers the buttons in question... Then returns the data so I can display it in the tooltip.
页面或表单本身不会改变,按钮也不会改变,只是包含在表单中的一个面板具有改变的“页面”,所以我需要能够编写一个函数来确定哪个页面是前一个页面,哪个页面是当鼠标悬停在有问题的按钮上时,页面是下一个……然后返回数据,以便我可以在工具提示中显示它。
Better Question; How can I pass any variable into a tooltip instead of setting it as a property.
更好的问题;如何将任何变量传递到工具提示而不是将其设置为属性。
回答by Karl Anderson
Given a tooltip named ToolTip1, then you can set variable text to a control, like this:
给定一个名为 的工具提示ToolTip1,然后您可以将变量文本设置为控件,如下所示:
Dim myToolTipText = "Dummy text"
ToolTip1.SetToolTip(Me.Button1, myToolTipText)
回答by user3159666
I wanted to assign the button's text to the tooltip title at runtime. I used the following code:
我想在运行时将按钮的文本分配给工具提示标题。我使用了以下代码:
Private Sub ToolTip1_Popup(sender As Object, e As System.Windows.Forms.PopupEventArgs) _
Handles ToolTip1.Popup
ToolTip1.ToolTipTitle = e.AssociatedControl.Text
End Sub

