Hi. Is there something similar in .NET components and if not, how to reproduce it?
Thanks!
Hi. Is there something similar in .NET components and if not, how to reproduce it?
Thanks!
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