ToolStrip的LineStyles净 [英] ToolStrip LineStyles .Net

查看:121
本文介绍了ToolStrip的LineStyles净的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有.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

这篇关于ToolStrip的LineStyles净的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆