简体   繁体   中英

How do I add an Image Tooltip on MouseHover?

I was wondering if there's a way to create an image tooltip on a mousehover event for a button for a form in Visual Studio Community 2013.

Ideally, the image is displayed constantly a little bit above the cursor and moves with the cursor as long as the cursor is above the button.

I am guessing that I can't use the Tooltip object for this, from what I have researched, so I was wondering what way to go about it.

Try placing the ToolTip component on your form and a button control:

Protected Overrides Sub OnLoad(e As EventArgs)
  MyBase.OnLoad(e)
  ToolTip1.OwnerDraw = True
  ToolTip1.SetToolTip(Button1, "This is a tool tip message for the button.")
End Sub

Private Sub ToolTip1_Popup(sender As Object, e As PopupEventArgs) Handles ToolTip1.Popup
  e.ToolTipSize = New Size(200, 64)
End Sub

Private Sub ToolTip1_Draw(sender As Object, e As DrawToolTipEventArgs) Handles ToolTip1.Draw
  e.Graphics.Clear(SystemColors.Info)
  e.Graphics.DrawImage(SystemIcons.Application.ToBitmap(), New Point(16, 16))
  TextRenderer.DrawText(e.Graphics, e.ToolTipText, e.Font, _
                        New Rectangle(64, 8, e.Bounds.Width - 72, e.Bounds.Height - 16), _
                        SystemColors.InfoText, Color.Empty, _
                        TextFormatFlags.WordBreak Or TextFormatFlags.VerticalCenter)
End Sub

Result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM