Sunday 8 May 2011

TabControl in C#

Tabcontrol Control
The TabControl provides an easy way of organizing a dialog into logical parts that can be accessed through tabs located at the top of the control. A TabControl contains TabPages that essentially work in a similar way to a GroupBox control, though it is somewhat more complex:
                                          
TabControl Properties
Name
Availability
Description
Alignment Read/Write Controls where on the tab control the tabs are displayed. The default is at the top.
Appearance Read/Write Controls how the tabs are displayed. The tabs can be displayed as normal buttons or with flat style.
HotTrack Read/Write If this property is set to true the appearance of the tabs on the control change as, the mouse pointer passes over them.
Multiline Read/Write If this property is set to true, it is possible to have several rows of tabs.
RowCount Read-only Returns the number of rows of tabs that is currently displayed.
SelectedIndex Read/Write Returns or sets the index of the selected tab.
TabCount Read-only Returns the total number of tabs.
TabPages Read-only This is the collection of TabPages in the control. Use this collection to add and remove TabPages.
Working with TabControl
       Drag and drop a TabControl and add pages as show in below picture.
                                                     

Now change the text property of the TabControl tab page as shown in below picture.
Design according to your choice or shown in below image.
                                                    
Code for picking date- for this add a month calendar and make visibility false and true its visibility on PickDate button click.

private void button1_Click(object sender, EventArgs e)
        {
            monthCalendar1.Visible = true;
        }

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            textBox3.Text = DateTime.Now.ToLongDateString();
            monthCalendar1.Visible = false;
        }
                                                    
On clicking next button you can move on next TabIndex code for this is given below-

 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
            {
                MessageBox.Show("Please fill your personal information");

            }
            else
            {
                this.tabControl1.SelectedIndex = 1;
            }
            
           
        }

                                                  

                                                  

                                                  

Code for previous button Click-

private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.tabControl1.SelectedIndex = 0;
        }

No comments:

Post a Comment