如何在 VB.NET 中的图像上创建鼠标悬停工具提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4056980/
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
How Can I Create a Mouseover Tooltip on an Image in VB.NET?
提问by Lou
Can I create a tooltip that will show up when a user moves his/her cursor over an image? I can't find such a property in Visual Studio, and I've scoured Google to no avail. I'm using an image in a PictureBox.
我可以创建一个工具提示,当用户将他/她的光标移到图像上时会显示吗?我在 Visual Studio 中找不到这样的属性,而且我在 Google 上搜索也无济于事。我在 PictureBox 中使用图像。
Here's to anyone out there on StackOverflow instead of some awesome Halloween party! Yay!
这是给 StackOverflow 上的任何人,而不是一些很棒的万圣节派对!好极了!
回答by jasper
yea, for some reason the Picturebox doesnt have one.
是的,出于某种原因,Picturebox 没有。
imports System.Drawing
dim tt as new ToolTip()
tt.SetToolTip(picPicture, "This is a picture")
and dont worry, the weekend has only started, plenty of time to party.
别担心,周末才刚刚开始,有充足的时间来聚会。
回答by Bryan Allred
Typically I create the interface then throw a ToolTip object from the Toolbox on to the form.
通常我创建界面然后将 ToolTip 对象从工具箱扔到表单上。
This then gives each object the "ToolTip" property (towards the bottom of the list) which can then be configured to your delight.
然后为每个对象提供“工具提示”属性(朝向列表底部),然后可以根据您的喜好进行配置。
回答by betrice mpalanzi
Drag a ToolTip control from the toolbox on the left onto your form (the designer will then put it below your form, since it's not meant to be visible normally). By default it will be named "tooltip1".
将 ToolTip 控件从左侧的工具箱拖到您的表单上(然后设计者会将它放在您的表单下方,因为它通常不可见)。默认情况下,它将被命名为“tooltip1”。
Then select your checkbox and go over to its properties window. You should see a property labeled "Tooltip on tooltip1" - set this to whatever you want. When you run the app and hold the mouse over your checkbox, you should see the tooltip text.
然后选择您的复选框并转到其属性窗口。您应该会看到一个标记为“tooltip1 上的工具提示”的属性 - 将其设置为您想要的任何内容。当您运行应用程序并将鼠标悬停在复选框上时,您应该会看到工具提示文本。
回答by JaredPar
Assuming that you have added a picture box member with the WithEvents
modifier you can use the following
假设您已经添加了带有WithEvents
修饰符的图片框成员,您可以使用以下内容
Private tt As ToolTip = New ToolTip()
Sub OnPictureMouseHover(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.MouseHover
tt.Show("the message", Me)
End Sub
Sub OnPictureMouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.MouseLeave
tt.Hide()
End Sub