Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add a NumericUpDown Control to a StatusStrip VB 2008

How-to

How to add a NumericUpDown Control to a StatusStrip VB 2008

by  Sorwen  Posted    (Edited  )
The Status Strip is very nice to have on a form, but doesn't contain all of the controls you might need. So here is an example of how to add a NumericUpDown control. So a status strip can "see" your control automatically you will need to create a separate .dll for it.

Code:
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

<System.ComponentModel.DesignerCategory("code")> _
<ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)> _
Public Class ToolStripStatusNumericUpDown
    Inherits Windows.Forms.ToolStripControlHost

    Public Sub New()
        MyBase.New(New Windows.Forms.NumericUpDown)
    End Sub

    <System.ComponentModel.Browsable(False)> _
    Public ReadOnly Property NumericUpDownControl() As Windows.Forms.NumericUpDown
        Get
            Return CType(Control, Windows.Forms.NumericUpDown)
        End Get
    End Property

    Public Property value() As Integer
        Get
            Return NumericUpDownControl.Value
        End Get
        Set(ByVal value As Integer)
            NumericUpDownControl.Value = value
        End Set
    End Property

    Protected Overrides Sub OnSubscribeControlEvents(ByVal control As System.Windows.Forms.Control)
        MyBase.OnSubscribeControlEvents(control)

        Dim valueNumericUpDownControl As NumericUpDown = CType(control, NumericUpDown)
        AddHandler valueNumericUpDownControl.ValueChanged, AddressOf NumericUpDownControl_ValueChanged
    End Sub

    Protected Overrides Sub OnUnsubscribeControlEvents(ByVal control As System.Windows.Forms.Control)
        MyBase.OnUnsubscribeControlEvents(control)

        Dim valueNumericUpDownControl As NumericUpDown = CType(control, NumericUpDown)
        RemoveHandler valueNumericUpDownControl.ValueChanged, AddressOf NumericUpDownControl_ValueChanged
    End Sub

    Public Event ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Private Sub NumericUpDownControl_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        RaiseEvent ValueChanged(sender, e)
    End Sub
End Class

You should be able to add other controls in the same manner.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top