ToolStrip LineStyles .Net

时间:2010-04-22 10:43:18

标签: .net winforms color-picker

.NET组件中是否有类似内容,如果没有,如何重现它?

alt text http://lh6.ggpht.com/_1TPOP7DzY1E/S9Ap9jAPheI/AAAAAAAADK0/rNwXMyz0I9U/s800/Capture8.png

谢谢!

1 个答案:

答案 0 :(得分:1)

没有这样的控件,但ToolStripControlHost Class将允许您创建自己的自定义ToolStrip控件。

更新:检查这堂课我很快就掀起了

Public Class LineStyleMenuItem
    Inherits Windows.Forms.ToolStripMenuItem

Private style As Drawing2D.DashStyle
Public Property LineStyle() As Drawing2D.DashStyle
    Get
        Return style
    End Get
    Set(ByVal value As Drawing2D.DashStyle)
        style = value
    End Set
End Property

    Public Sub New(ByVal style As Drawing2D.DashStyle)
        Me.style = style
    End Sub

    Private Sub LineStyleMenuItem_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Const line_width As Integer = 6
        Const padding As Integer = 6
        Dim y As Single = CSng((Me.Height / 2) - (line_width / 2))
        Dim p As New Drawing.Pen(Color.Black, line_width)
        p.DashStyle = style
        e.Graphics.DrawLine(p, padding, y, Me.Width - padding, y)
        p.Dispose()
    End Sub

End Class

您可以通过向“工具条下拉”控件添加项目来使用它:

    dropdownbutton.DropDownItems.Add(New LineStyleMenuItem(Drawing2D.DashStyle.Dash))
    dropdownbutton.DropDownItems.Add(New LineStyleMenuItem(Drawing2D.DashStyle.DashDot))
    dropdownbutton.DropDownItems.Add(New LineStyleMenuItem(Drawing2D.DashStyle.DashDotDot))
    dropdownbutton.DropDownItems.Add(New LineStyleMenuItem(Drawing2D.DashStyle.Dot))
    dropdownbutton.DropDownItems.Add(New LineStyleMenuItem(Drawing2D.DashStyle.Solid))

并按如下方式访问点击的项目样式:

Private Sub dropdownbutton_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles dropdownbutton.DropDownItemClicked
    MsgBox(CType(e.ClickedItem, LineStyleMenuItem).LineStyle)
End Sub