【问题标题】:How do I format the tooltip used by a DataGridView in virtual mode?如何格式化 DataGridView 在虚拟模式下使用的工具提示?
【发布时间】:2009-01-28 12:49:31
【问题描述】:

我需要将格式(特别是粗体文本)应用到 DataGridView 在虚拟模式下使用的工具提示。我可以在 CellToolTipTextNeeded 事件中设置文本,但它不支持 HTML 标签;我应该使用其他语法吗?我不想自己重新实现工具提示支持。

【问题讨论】:

    标签: c# .net datagridview tooltip


    【解决方案1】:

    您可以使用 HtmlToolTip 从 http://www.codeproject.com/KB/GDI-plus/HtmlRenderer.aspx

    To use it with DataGridView create a ToolTip (HtmlToolTip) and add this after the InitalizeComponent() in your form to replace the default tooltip:
    
    System.Reflection.FieldInfo toolTipControlFieldInfo=
    typeof(DataGridView).GetField("toolTipControl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    
    System.Reflection.FieldInfo toolTipFieldInfo=
    toolTipControlFieldInfo.FieldType.GetField("toolTip", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    
    object toolTipControlInstance =
    toolTipControlFieldInfo.GetValue(myDataGridView);
    
    toolTipFieldInfo.SetValue(toolTipControlInstance, myToolTip);
    

    使用 .net 3.5 为我工作

    【讨论】:

      【解决方案2】:

      正如事件名称所暗示的那样,它只是希望显示文本,不会有格式。

      如果您想要粗体或其他类型的格式,您将不得不自己处理工具提示的显示和绘制。您可以使用 ToolTip 控件来提供帮助,将 OwnerDraw 属性设置为 true 并处理 Draw 事件,但请注意,您很可能必须以重要的方式覆盖网格才能在适当的时间进入该事件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多