Export (0) Print
Expand All

TrackBar.TickStyle Property

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public TickStyle TickStyle { get; set; }

Property Value

Type: System.Windows.Forms.TickStyle
One of the TickStyle values. The default is TickStyle.BottomRight.

ExceptionCondition
InvalidEnumArgumentException

The assigned value is not a valid TickStyle.

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

The following code example demonstrates how to use the TickStyle, Minimum, and Maximum properties and how to handle the ValueChanged event. To run the example, paste the following code into a form that contains a TrackBar control named TrackBar1 and a TextBox control named TextBox1. Call the InitializeTrackBar method from the form's constructor or Load event-handling method.



	//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();
	}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft