Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> C# >> How to use Track Bar Control in C#
How to use Track Bar Control in C#
How to use Track Bar Control in C#


by Awadhendra Tiwari on 1/21/2011 3:31:41 PM

Views: 12504       Comments: 0

How to use TrackBar Control in C#

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.

How to use Track Bar Control in C#

The TrackBar control has two parts. Slider and, 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 which are spaced at regular intervals.

This example demonstrates the use of track bar. In this example I had taken two labels which shows message such as values in centigrade and values in farehenhite. I had taken two textbox’s also. In first text box I enter value in centigrade and in second text box we get output in farehenhite. A TrackBar control shows the value in centigrade. If the value in textbox1 is entered 29 then slider moves on 29th division and appropriate farehenhite a value is shown in textbox. As well as we move slider on TrackBar then it also changes the value in centigrade as well as farehenhite.

Useful properties of TrackBar Control

·         Maximum The maximum value for the position of the slider on the TrackBar control. This property takes an integer types value.

·         Minimum The minimum value for the position of the slider on the TrackBar control. This property takes an integer types value.

·         Orientation The orientation of TrackBar control. That should be either horizontal or vertical.

·         Large Change The number of position the slider moves in response of mouse click page up and page down button.

·         Small Change The number of positions the slider moves in response of keyboard value.

·         Value The position of the slider on TrackBar control.

 

private void txtCentiGrade_TextChanged(object sender, EventArgs e)//Text change event of the textbox control

            //as well as we made any changes in textbox control then text change event is called

        {

            if (txtCentiGrade.Text.Trim().Length > 0)//count the length of the textbox control.If it is greater than

                //0 then value of textbox control is converted into farhenhite.

            {

                try

                {

                    int centigrade = Convert.ToInt32(txtCentiGrade.Text);//string values is converted in integer format

                    if (centigrade > 300)//maximum value in centigrade that track bar control can show.

                    {

                        MessageBox.Show("The value in a centigrade should be less than 300");

                        return;

                    }

                    float forehenhite = changeForehenHite(centigrade);//call changeForhenhite(int centigrade) methods

                    //which convert centigrade values in farhenhite values.

                    slider1.Value = centigrade;//moves slider on appropriate position on trackbar control.

                    txtForehenHite.Text = forehenhite.ToString();//display values in second textbox control.

                }

                catch (Exception e1)

                {

                    MessageBox.Show(e1.Message);

                }

            }

            else

            {

                slider1.Value = 0;//if length of the textbox1 is zero then it store the position of the slider on 0

                txtForehenHite.Text = "";

            }

        }

        public float changeForehenHite(int centigrade)//A method which convert centigrade values in farhenhite values.

        {

            float forehenhite = 0;

            forehenhite = ((centigrade * 9) / 5) + 32;

            return forehenhite;           

        }

        private void slider1_Scroll(object sender, EventArgs e)//When we moves slider on trackbar control then

            //slider1_Scroll() event is called.

        {

            float num = changeForehenHite(slider1.Value);

            txtForehenHite.Text = num.ToString();

            txtCentiGrade.Text = slider1.Value.ToString();

        }

    }

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 3649
Advertisement
MindStick Cleaner
Advertise with Us
  
Copyright © 2014MindStick. All Rights Reserved.