Results 1 to 18 of 18

Thread: ToolStripCheckBox

Threaded View

  1. #1

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


    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:
    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
                Return TryCast(Control, CheckBox)
            End Get
        End Property
        Public Property ToolStripCheckBoxEnabled() As Boolean
                Return ToolStripCheckBoxControl.Enabled
            End Get
            Set(ByVal value As Boolean)
                ToolStripCheckBoxControl.Enabled = value
            End Set
        End Property
        Public Property Checked() As Boolean
                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)
            AddHandler DirectCast(c, CheckBox).CheckedChanged, AddressOf OnCheckedChanged
        End Sub
        Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
            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: 1939
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


Click Here to Expand Forum to Full Width

Survey posted by VBForums.