Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Using Timer in C#

1,Drag & drop timer from Visual Studio tool box

2,To start timer
timer1.Start();
3,To Stop Timer
timer1.Stop();
4,Timer Tick event (Executes every second if timer started) 

private void timer1_Tick(object sender, EventArgs e)
{
commands
}

5,To count down using Timer

private void timer1_Tick(object sender, EventArgs e)
{
label3.Text = (Convert.ToInt32(label3.Text) - 1).ToString();
}




Easy way to handle combo box in C#

1,Drag & drop Combo box in form in visual studio
2,Assign list like below picture






















3,Assign default value in Combo box when form load

private void Form1_Load(object sender, EventArgs e)
        {
            
            comboBox1.SelectedIndex = 0;
        }
 

4,Double click on combo box will show SelectedIndexChanged event,Use Switch command to write your different event code.

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex){

                case 0: shutdown = "-s"; break;
                case 1: shutdown = "-r"; break;
                case 2: shutdown = "-l"; break;

            
            
            }




^ Top