ToolStrip的LineStyles净ToolStrip、LineStyles

由网友(凉心骚年i)分享简介:是否有.NET组件类似的东西,如果没有,如何重现呢?Is there something similar in .NET components and if not, how to reproduce it?谢谢!推荐答案没有没有这样的控制,但的 ToolStripControlHost类将允许您创建自己的自定义...

是否有.NET组件类似的东西,如果没有,如何重现呢?

Is there something similar in .NET components and if not, how to reproduce it?

谢谢!

推荐答案

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

No there is no such control, but the ToolStripControlHost Class will allow you to create your own custom ToolStrip controls.

更新:检查该类我迅速刮起了

Update: Check this class I quickly whipped up

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

您可以通过将项目添加到工具条下拉控制使用它:

You can use it by adding items to a Toolstrip Dropdown control:

    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))

和访问点击项目样式像这样:

And access the clicked item style like so:

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
阅读全文

相关推荐

最新文章