1

使用很少的静态contextmenustrip项目,我可以像这样动态地从数据库中创建其他项目:

reader = cmd.ExecuteReader()
If reader.HasRows Then Arh_ContextMenuStrip.Items.Add("-", Nothing, Nothing)
While (reader.Read())
    If CStr(reader.GetValue(0)).Length = 17 And Not CStr(reader.GetValue(0)) = mydatabase Then
        Arh_ContextMenuStrip.Items.Add(CStr(reader.GetValue(0)), Nothing, AddressOf myHandler_Click)
        'How to set font "Courier New" for this item?
        'How to set tooltip for this item?
    End If
End While

问题是:我可以以及如何为此类项目设置不同的字体,例如“Courier New”,并为每个此类项目添加工具提示文本。那是因为我需要这些项目的比例字体。

4

1 回答 1

1

试试这个,

While (reader.Read())

     If CStr(reader.GetValue(0)).Length = 17 And Not CStr(reader.GetValue(0)) _
     = mydatabase Then

        'Adding item into a context menu strip will return the same.
        Dim xAddedItem = Arh_ContextMenuStrip.Items.Add(CStr(reader.GetValue(0)), _
        Nothing,AddressOf myHandler_Click)

        'Set Different fonts matching your requirement
        xAddedItem .Font = New Font("Courier New", 14, FontStyle.Bold)
        xAddedItem .ToolTipText = "Hello I'm the tool tip"

    End If

End While
于 2013-03-14T09:22:32.557 回答