views:

27

answers:

1

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

alt text

Thanks!

+1  A: 

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
Wez
interesting. However, before hosting I should first create something to host :)
serhio
Yup, that's the idea. Funny I don't find any line-style selector tools, which means no one in the public has made one yet. Perhaps a combobox with custom drawn items...
Wez