Monday, February 28, 2011

TrackBar

TrackBar

 A TrackBar control provides a simple interface that allows the user to set a value from a fixed range of values by graphically manipulating a slider with the mouse or keyboard.





The TrackBar control has two parts: the slider, and the tick marks. The slider is the part that can be adjusted with its position corresponding to the Value property. The tick marks are visual indicators that are spaced at regular intervals. The trackbar moves in increments that you specify and can be aligned horizontally or vertically.

Inheritance hierarchy

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      System.Windows.Forms.Control
        System.Windows.Forms.TrackBar

Useful properties

  • LargeChange - Indicates the value to be added to or subtracted from the Value property when the slider is moved a large distance. This is the number of positions the slider moves in response to having the PAGE UP or PAGE DOWN key pressed, or in response to mouse clicks on the track bar on either side of the slider.
  • Maximum - Indicates the upper limit of the range this TrackBar is working with.
  • Minimum - Indicates the lower limit of the range this TrackBar is working with.
  • Orientation - Gets or sets a value indicating the horizontal or vertical orientation of the track bar. When the Orientation property is set to Orientation.Horizontal, the scroll box moves from left to right as the Value increases. When the Orientation property is set to Orientation.Vertical, the scroll box moves from bottom to top as the Value increases.
  • SmallChange - Indicates the value added to or subtracted from the Value property when the slider is moved a small distance. This is the number of positions the slider moves in response to having the LEFT or RIGHT ARROW key pressed. UP or DOWN ARROW key pressed in vertical orientation.
  • TickFrequency - Determines a value that specifies the delta between ticks drawn on the control.
  • TickStyle - Indicates how to display the tick marks on the track bar. Takes a value from the TickStyle enumeration:
  • Both - Tick marks are located on both sides of the control.
  • BottomRight - Tick marks are located on the bottom of a horizontal control or on the right side of a vertical control.
  • None - No tick marks appear in the control.
  • TopLeft - Tick marks are located on the top of a horizontal control or on the left of a vertical control.
  • Value - A numeric value that represents the current position of the slider on the track bar. 

Adding a TrackBar manually 

 

You can add a TrackBar to a form at run time in the following manner.
public void AddTrackBar()
{
  TrackBar tb1 = new TrackBar();
  tb1.Location = new Point(10, 10);
  tb1.Size = new Size(250, 50);
 
  tb1.Minimum = 0;
  tb1.Maximum = 100;
 
  tb1.SmallChange = 1;
  tb1.LargeChange = 5;
 
  tb1.TickStyle = TickStyle.BottomRight;
  tb1.TickFrequency = 10;
 
  tb1.Value = 10;
 
  Controls.Add(tb1);
}
 

MSDN references

 




No comments:

Post a Comment