Windows Develop Bookmark and Share   
 index > Windows Forms General > Add TrackBar in StatusStrip
 

Add TrackBar in StatusStrip

Hi everyone,
I would add TrackBar Control in StatusStrip.
The code to add items in StatusStrip admits just ToolStripItem
like:

Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripStatusLabel1, Me.ToolStripProgressBar1})

TrackBar inherits from Control, so it’s not possible to add in StatusStrip.items.
ToolStripProgressBar has been created similar to ProgressBar Control and ‘adjusted�for ToolStripItem, is it possible to do the same with TrackBar?


Thanks and regards,
Mauro

MauroGv  Sunday, April 06, 2008 3:33 PM
hi
you can use ToolStripControlHost like this :

Code Snippet

ToolStripControlHost myControlHost = new ToolStripControlHost(new TrackBar());
statusStrip1.Items.Add(myControlHost);

I am Emran  Sunday, April 06, 2008 3:56 PM

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

MauroGv  Monday, April 07, 2008 8:52 AM
hi
you can use ToolStripControlHost like this :

Code Snippet

ToolStripControlHost myControlHost = new ToolStripControlHost(new TrackBar());
statusStrip1.Items.Add(myControlHost);

I am Emran  Sunday, April 06, 2008 3:56 PM

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

MauroGv  Monday, April 07, 2008 8:52 AM

You can use google to search for other answers

Custom Search

More Threads

• Exposing a button from a user control as the cancel button
• Collapse node
• Screen Refresh taking Forever
• ToolStripMenuItem Shortcut on culture change
• Biringing a run-time created textBox in front of a treeView
• Question about accessing objects stored in hashtables within objects
• Is possible to change the visual of controls?
• Help with getting a index from a listBox
• if statement (test statement)
• I am at a total loss on this issue