Hi,
thanks for your good offices.
I've personalizedToolStripMenuItem using class ToolStripControlHost passing TrackBar in instance.
I add Event to handle when the TrackBar is scrolled.
This is the code:
'Declare a class that inherits from ToolStripControlHost.
Public Class ToolStripTrackBar
Inherits ToolStripControlHost
' Call the base constructor passing in a TrackBar instance.
Public Sub New()
MyBase.New(New TrackBar())
'Starting Values propertiesI want when the control is initialized
TrackBarControl.TickFrequency = 10
Me.TrackBarControl.Maximum = 60
Me.TrackBarControl.Minimum = 1
Me.TrackBarControl.BackColor = Color.FromKnownColor(KnownColor.ControlDark)
End Sub
Public ReadOnly Property TrackBarControl() As TrackBar
Get
Return CType(Control, TrackBar)
End Get
End Property
' Expose the TrackBar's Value without using property above
Public Property Value() As Single
Get
Return TrackBarControl.Value
End Get
Set(ByVal value As Single)
TrackBarControl.Value = value
End Set
End Property
' Subscribe and unsubscribe the control events you wish to expose.
Protected Overrides Sub OnSubscribeControlEvents(ByVal c As Control)
' Call the base so the base events are connected.
MyBase.OnSubscribeControlEvents(c)
' Cast the control to a Track control.
Dim TrackBar As TrackBar = CType(c, TrackBar)
' Add the event.
AddHandler TrackBar.Scroll, AddressOf HandleScroll
End Sub
Protected Overrides Sub OnUnsubscribeControlEvents(ByVal c As Control)
' Call the base method so the basic events are unsubscribed.
MyBase.OnUnsubscribeControlEvents(c)
' Cast the control to a Track control.
Dim TrackBar As TrackBar = CType(c, TrackBar)
' Remove the event.
RemoveHandler TrackBar.Scroll, AddressOf HandleScroll
End Sub
' Declare the ValueChanged event.
Public Event Scroll As EventHandler
' Raise the DateChanged event.
Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)
RaiseEvent Scroll(Me, e)
End Sub
End Class
Best Regards,
Mauro