Export (0) Print
Expand All

TrackBar.TickStyle Property

Gets or sets a value indicating how to display the tick marks on the track bar.

[Visual Basic]
Public Property TickStyle As TickStyle
[C#]
public TickStyle TickStyle {get; set;}
[C++]
public: __property TickStyle get_TickStyle();
public: __property void set_TickStyle(TickStyle);
[JScript]
public function get TickStyle() : TickStyle;
public function set TickStyle(TickStyle);

Property Value

One of the TickStyle values. The default is TickStyle.BottomRight.

Exceptions

Exception Type Condition
InvalidEnumArgumentException The assigned value is not one of the valid TickStyle values.

Remarks

You can use the TickStyle property to modify the manner in which the tick marks are displayed on the track bar.

Example

[Visual Basic, C#] The following code example demonstrates how to use the TickFrequency, Minimum, and Maximum members and how to handle the ValueChanged event. To run the example, place the following code in a form containing a TrackBar control called TrackBar1 and a TextBox control called TextBox1. Call the InitializeTrackBar method the form's constructor or Load method.

[Visual Basic] 

    'Declare a new TrackBar object.
    Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar

    ' Initalize the TrackBar and add it to the form.
    Private Sub InitializeTrackBar()
        Me.TrackBar1 = New System.Windows.Forms.TrackBar

        ' Set the TickStyle property so there are ticks on both sides
        ' of the TrackBar.
        TrackBar1.TickStyle = TickStyle.Both

        ' Set the minimum and maximum number of ticks.
        TrackBar1.Minimum = 10
        TrackBar1.Maximum = 100

        ' Set the tick frequency to one tick every ten units.
        TrackBar1.TickFrequency = 10

        TrackBar1.Location = New System.Drawing.Point(75, 30)
        Me.Controls.Add(Me.TrackBar1)
    End Sub


    ' Handle the TrackBar.ValueChanged event by calculating a value for
    ' TextBox1 based on the TrackBar value.  
    Private Sub TrackBar1_ValueChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
        TextBox1.Text = System.Math.Round(TrackBar1.Value / 10)
    End Sub

[C#] 

    //Declare a new TrackBar object.
    internal System.Windows.Forms.TrackBar TrackBar1;

    // Initalize the TrackBar and add it to the form.
    private void InitializeTrackBar()
    {
        this.TrackBar1 = new System.Windows.Forms.TrackBar();
        TrackBar1.Location = new System.Drawing.Point(75, 30);

        // Set the TickStyle property so there are ticks on both sides
        // of the TrackBar.
        TrackBar1.TickStyle = TickStyle.Both;

        // Set the minimum and maximum number of ticks.
        TrackBar1.Minimum = 10;
        TrackBar1.Maximum = 100;

        // Set the tick frequency to one tick every ten units.
        TrackBar1.TickFrequency = 10;

        // Associate the event-handling method with the 
        // ValueChanged event.
        TrackBar1.ValueChanged += 
            new System.EventHandler(TrackBar1_ValueChanged);
        this.Controls.Add(this.TrackBar1);
    }
    

    // Handle the TrackBar.ValueChanged event by calculating a value for
    // TextBox1 based on the TrackBar value.  
    private void TrackBar1_ValueChanged(object sender, System.EventArgs e)
    {
        TextBox1.Text = (System.Math.Round(TrackBar1.Value/10.0)).ToString();
    }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

TrackBar Class | TrackBar Members | System.Windows.Forms Namespace | TickStyle

Show:
© 2014 Microsoft