ToolStripCheckBox-VBForums
Results 1 to 16 of 16

Thread: ToolStripCheckBox

Threaded View

  1. #1

    Thread Starter
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,817

    ToolStripCheckBox

    I've recently wanted a CheckBox in a ToolStrip and while that control doesn't exist in the framework, I did some googling and made my own:
    Code:
    Imports System.Windows.Forms.Design
    
    <ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip), DebuggerStepThrough()> _
    Public Class ToolStripCheckBox
        Inherits ToolStripControlHost
    
        Public Sub New()
            MyBase.New(New System.Windows.Forms.CheckBox())
            ToolStripCheckBoxControl.BackColor = Color.Transparent
        End Sub
    
        Public ReadOnly Property ToolStripCheckBoxControl() As CheckBox
            Get
                Return TryCast(Control, CheckBox)
            End Get
        End Property
    
        Public Property ToolStripCheckBoxEnabled() As Boolean
            Get
                Return ToolStripCheckBoxControl.Enabled
            End Get
            Set(ByVal value As Boolean)
                ToolStripCheckBoxControl.Enabled = value
            End Set
        End Property
    
        Public Property Checked() As Boolean
            Get
                Return ToolStripCheckBoxControl.Checked
            End Get
            Set(ByVal value As Boolean)
                ToolStripCheckBoxControl.Checked = value
            End Set
        End Property
    
        Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control)
            MyBase.OnSubscribeControlEvents(c)
            AddHandler DirectCast(c, CheckBox).CheckedChanged, AddressOf OnCheckedChanged
        End Sub
    
        Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
            MyBase.OnUnsubscribeControlEvents(c)
            RemoveHandler DirectCast(c, CheckBox).CheckedChanged, AddressOf OnCheckedChanged
        End Sub
    
        Public Event CheckedChanged As EventHandler
    
        Private Sub OnCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            RaiseEvent CheckedChanged(Me, e)
        End Sub
    End Class
    Just add that code to your project , build it then simply click the AddItem DropDown arrow on a ToolStrip and at the bottom, there it is.

    Here's a screenshot of it being used:
    Name:  ToolStripCheckBoxExample.png
Views: 1328
Size:  75.5 KB

    I've also included a class file as well as an example project for this.
    Attached Files Attached Files
    Last edited by JuggaloBrotha; Jul 25th, 2012 at 08:10 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.