PropertyGrid提示超链接?

时间:2015-09-03 09:35:45

标签: c# winforms propertygrid

是否可以在属性网格提示中添加可点击的超链接?

我的课程中有以下内容(已将属性网格指定为SelectedObject):

[Browsable(true), 
ReadOnly(false), 
Category("7. InnoDB"), 
DefaultValue(1), 
Description("Defines what happens after InnoDB transaction commit, for more details view https://mariadb.com/kb/en/mariadb/xtradbinnodb-server-system-variables/#innodb_flush_log_at_trx_commit")]
public int innodb_flush_log_at_trx_commit { get; set; } = 1;

在属性网格中查看时,该链接无法点击。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

查看MSDN参考,PropertyGrid使用两个Label,一个用于标题,一个用于描述:

http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/PropertyGridInternal/DocComment.cs,a0b78590be82b950

Label不支持超链接。您可以做的是在描述标签上放置RichTextBox,然后让它显示文本。 E.g。

    PropertyGrid pg = new PropertyGrid() { Dock = DockStyle.Fill };
    Control c = pg.Controls[0]; // internal DocComment control
    Label l1 = (Label) c.Controls[1];
    RichTextBox tb = new RichTextBox { Multiline = true, WordWrap = true, ReadOnly = true, BorderStyle = BorderStyle.None };
    c.Controls.Add(tb);
    c.Controls.SetChildIndex(tb, 0);
    l1.TextChanged += delegate {
        tb.Text = l1.Text;
    };
    l1.SizeChanged += delegate {
        tb.Size = l1.Size;
    };
    l1.LocationChanged += delegate {
        tb.Location = l1.Location;
    };