Thursday, September 20, 2012

Windows Form Controls (Finished)

Take a look at the attached code. Here I demonstrate a example of the dateTimePicker, radioButton and richTextBox Control.
Download Here

1. Open the IDE.
2. Add three labels and change the Text Property to Name, Date of Birth and Sex.
3. Add a textBox, a dateTimePicker and two radioButton control horizontally parallel to the labels.
4. Add a button and set Text propery to Submit.
5. Last of all add a richTextBox control at the bottom of the Form.
6. Double click the submit button and add the following codes.

            string gender;
            if(radioButton1.Checked)
            {
                gender = radioButton1.Text;
            }
            else
            {
                gender = radioButton2.Text;
            }
            richTextBox1.Text = "My Name is " + textBox1.Text + "\nMy Date of Birth is " +
                                dateTimePicker1.Value.ToLongDateString() +
                                "\nMy gender is " + gender;

7. The if else statement checks the states of the radioButton. Then it decide wheather you are a male or female.
8. Then its sets the richTextBox Text property to a string which is a concatenation of the textBox, dateTimePicker control's and gender variable value.

No comments:

Post a Comment