【问题标题】:how to add image to tooltip using vb.net?如何使用 vb.net 将图像添加到工具提示?
【发布时间】:2014-02-12 10:06:44
【问题描述】:

我正在使用 Visual Studio 2012(获胜表格)

我想为我的文本框和标签添加带有标题的说明图像,我尝试将工具提示仅作为文本,效果很好,但我想向它们添加图像,就像这里阐明的示例一样: (https://www.youtube.com/watch?v=iGuBIqVUc5c&feature=youtu.be)

我在这里搜索了主题,但我发现的唯一一个是我不熟悉的 c#,所以任何在 vb.net 中使用它的帮助都会很棒。 知道属性窗口中唯一可用的属性是“工具提示 1 的工具提示”,与工具提示图像无关。

非常感谢..,

【问题讨论】:

  • 您不能使用 WinForms 工具提示控件执行此操作。只需创建一个带有适当文本和图像的表单,并在鼠标悬停事件触发时显示它?
  • @MattWilko 这是否意味着我必须为我的应用程序中的每个标签和文本制作表单?
  • 不只是创建一个包含图像和文本的通用表单并将它们公开为您可以在显示之前设置的属性
  • @MattWilko 抱歉,我只是这里的初学者,我不知道如何实现这个想法,任何指导帮助将不胜感激。,非常感谢
  • @MattWilko 请在这里提供任何指导帮助

标签: vb.net visual-studio tooltip


【解决方案1】:

您可以使用 Web Controls Image 控件 [System.Web.UI.WebControls.Image],只需通过设置该控件的 ToolTip 属性来设置工具提示。

【讨论】:

  • 我需要更多的说明,如何单独添加标题以及如何选择图像作为资源文件,我希望它与此处相同:(youtube.com/watch?v=iGuBIqVUc5c&feature=youtu.be)。工具提示属性也允许我只添加文本!
  • 感谢链接和这些丰富的信息,但这里的问题是我在属性窗口中关于工具提示的所有内容都是“工具提示 1 上的工具提示”,工具提示图像中没有任何内容,如链接
  • OwnerDraw 属性,如果为true,则工具提示的表面将由您的代码绘制,将引发Popup 和Draw 事件,否则将自行绘制工具提示表面。 OwnerDrawBackground 属性,如果为true,则工具提示的背景和表面都将由您的代码绘制,将引发Popup、DrawBackground 和Draw 事件,否则将自行绘制工具提示背景。
  • .,属性窗口中唯一可用的属性是“OwnerDraw”,我做到了,没有关于“OwnerDrawBackground 属性”的任何内容,如果您能澄清代码以使用工具提示,当鼠标悬停在任何标签上方时(例如)。感谢您的努力
【解决方案2】:

这是一个快速而肮脏的 hack,它使用作为资源存储在项目文件中的图像

Public Class ImageTip
    Inherits ToolTip

    Public Sub New()
        MyBase.New()
        Me.OwnerDraw = True 'Must be set otherwise will not draw the image properly
        Me.IsBalloon = False
    End Sub

    Private Sub ImageTip_Draw(ByVal sender As Object, ByVal e As DrawToolTipEventArgs) _
                Handles Me.Draw
        'Draws the image in the tooltip popup by reading the tooltip
        'text on the control that you want to have a popup for
         e.Graphics.DrawImage(My.Resources.ResourceManager.GetObject(e.ToolTipText), 0, 0)
    End Sub

    Private Sub ImageTip_Popup(ByVal sender As Object, ByVal e As PopupEventArgs) _
                Handles Me.Popup
        'Creates the popup and sets its dimensions from the resource name
        Dim Image As Image
        Dim ToolText As String

        ToolText = Me.GetToolTip(e.AssociatedControl)
        If ToolText <> "" Then
            Image = My.Resources.ResourceManager.GetObject(ToolText)
            If Image IsNot Nothing Then
                e.ToolTipSize = New Size(Image.Width, Image.Height)
            Else
                e.Cancel = True
            End If
        End If
    End Sub
End Class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 2022-01-07
    • 2016-12-08
    相关资源
    最近更新 更多