在.NET组件中有类似的东西吗?如果没有,如何重现?
alt text http://lh6.ggpht.com/_1TPOP7DzY1E/S9Ap9jAPheI/AAAAAAAADK0/rNwXMyz0I9U/s800/Capture8.png
谢谢!
发布于 2010-04-22 19:59:11
不,没有这样的控件,但是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您可以通过将项添加到Toolstrip下拉控件来使用它:
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 Subhttps://stackoverflow.com/questions/2690044
复制相似问题