-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
1/12
Ask a Question
READER LEVEL:ARTICLE
This article explains the Tab Control and show how to use
it.
Learn Tab Control Using C#By Naveed Zaman on Jul 19, 2013
Download Files: Patients.rar
Acknowledgment Tab Control properties:
http://www.csharpcorner.com/uploadfile/mahesh/csharptabcontrol/
Tab Control
Dear reader, today we will discuss the Tab Control using C#. The
Tab Control is a very useful tool, especially indatabase
applications where we need to capture a huge number of data fields
on a single form. But we can use thiscontrol in other applications
as well.
How to use Tab Control in windows application?Important
properties of Tab Control?Simple sample application that
demonstratea the Tab Control using OOP.
So in simple words the Tab Control is useful where we don't want
to use many forms to display a large amount ofdata. Now we will
create the sample application that captures the data of a patient,
for example personal info tab,surgery info tab, discharges details
tab.
Step 1: First of all we will create the tables.
CREATE TABLE [dbo].[Patient_Info_Detail] [CRE_Patient_id]
[varchar]10 NOT NULL,[CRE_FirstName] [nvarchar]50
NULL,[CRE_LastName] [varchar]30 NULL,[CRE_Gender] [varchar]6
NULL,[CRE_Father_Name] [varchar]30 NULL,[CRE_Date_Of_Birth]
[datetime] NULL,[CRE_Address] [varchar]100 NULL,[CRE_City]
[varchar]100 NULL,[CRE_Phone1] [varchar]15 NULLCREATE TABLE
[dbo].[Patient_ surgery _Detail][OPR_Oper_Date] [datetime] NOT
NULL,[OPR_Oper_Id] [varchar]15 NOT NULL,[OPR_Oper_Patient_Id]
[varchar]10 NOT NULL,[OPR_Oper_Surgeon] [varchar]20 NOT
NULL,[OPR_Oper_Anaesthetist] [varchar]20 NOT
NULL,[OPR_Oper_Asssitant] [varchar]20 NOT NULL,CREATE TABLE
[dbo].[Discharge][DIS_Discharge_Patient_Id] [varchar]10 NOT
NULL,[DIS_Outgoing_Type] [nvarchar]20 NULL,[DIS_Date] [datetime]
NULL
Step 2: Now we will open the new project with the name
"patient_info".
01 Lotus Notes to SharePoint MigrationUsing QUEST02 Google+
Authentication in ASP.Net
03 Basics of AngularJS: Part 1
04 Angular JS Filter, Sorting andAnimation Using MVC and WCF
Rest05 How to Retrieve All Users From theGroup in SharePoint Using
REST API06 Creating Dynamic DataGridView UsingHelper Class07
Terminologies in MVC: Part 1(ViewData, ViewBag, TempData)08 MVC
AngularJS and WCF Rest ServiceFor Mind Reader Quiz09 Angular JS
Shopping Cart Using MVCand WCF Rest Service10 Basic Terminology of
SQL Server
View All
TRENDING UP
Follow@csharpcorner 14.6Kfollowers
In Focus MUST READ: Authors How to improve your Writing
Skills
Contribute
Lotus Notes to SharePoint Migration ... C#CornerSearch
22.1 k 3 1
FindusonFacebook
C#Corner
87,766peoplelikeC#Corner.
Like
Nagesh
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
2/12
Step 3: Now we will add the Tab Control from the tool bar.
TabControl Properties
Dear reader,C# provides the easiest way to set properties; from
the Properties Window. You can open theProperties window by
rightclicking on a control and selecting the Properties menu
item.
Name
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
3/12
The Name property represents a unique name of a TabControl
control. It is used to access the control in the code.The following
code snippet sets and gets the name and text of a TabControl
control.
C# Code:
tbPatient.Name = "TbPatient";
Positioning a TabControl
The Dock property is used to set the position of a TabControl.
It is of type DockStyle that can have one of the valuesTop, Bottom,
Left, Right, and Fill. The following code snippet sets Location,
Width, and Height properties of aTabControl control.
C# Code:
tbPatient.Dock = DockStyle.Left;
Font
The Font property represents the font of text of a TabControl
control. If you click on the Font property in Propertieswindow then
you will see Font name, size and other font options. The following
code snippet sets the Font propertyat runtime.
C# Code:
tbPatient.Font = new Font"Georgia", 16;
Background and Foreground
The BackColor and ForeColor properties are used to set the
background and foreground color of a TabControlrespectively. If you
click on these properties in the Properties window then the Color
Dialog pops up.
Alternatively, you can set the background and foreground colors
at runtime. The following code snippet sets theBackColor and
ForeColor properties.
C# Code:
tbPatient.BackColor = Color.White;tbPatient.ForeColor =
Color.Black;
Alignment and Appearance
The Alignment property gets or sets the area of the control
where the tabs are aligned. A TabAlignmentenumeration is used to
set the Alignment property and has one of the values Top, Bottom,
Left, or Right.
The Appearance property gets or sets the visual appearance of
the control's tabs. A TabAppearance enumeration isused to set the
Appearance property and has one of the values Normal, Buttons, or
FlatButtons.
C# Code:
tbPatient.Alignment=TabAlignment.Left;tbPatient.Appearance =
TabAppearance.FlatButtons;
Tab Pages
The TabPages property is a type of a TabPageColleciton object
and is the gateway to accessing and adding tabpages to a
TabControl. Like any other collection, the TabPageCollection has
all collection functionality includingadd, remove, and find.
We can add and access tab pages of a TabControl at designtime
from the Properties Window by clicking on theTabPages Collection as
you can see in Figure 4.
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
4/12
Figure 4
When you click on the Collections, the Tab Pages Collection
Editor window will popup where you can add andremove tab pages and
you can also set these tab pages properties and events. I add four
tab pages as you can seefrom Figure 5.
Figure 5
As we have seen earlier in this tutorial, we can also add and
remove tab pages to a TabControl using TabPage class.
Step 3: Now you need to design the form as shown in the
picture.
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
5/12
Step 4: Now we need to create four classes.
Main classPatient _Profile classsurgery classDiscahrge class
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
6/12
Now create two methods in the main class as given below. You can
change the SQL Server setting according toyour system.
Now add the second class Patient_Profile.
Now create the constructor of a class, one method in the
patient_profile class as given below.
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
7/12
Now add the surgery class.
Now add the following code in class surgery.
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
8/12
Now we create our fourth class.
Now add the following code:
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
9/12
Step 5: Dear readers, finaly we will add the code in the btnnext
click event.
private void btnnext_Clickobject sender, EventArgs e{if
tabControl1.SelectedTab.Text == "Patient
Info"{tabControl1.SelectedTab = tbOperation;}else if
tabControl1.SelectedTab.Text == "Operation"{tabControl1.SelectedTab
= tbDischarge;}}
Step 6: Now add the following code in the btnback button.private
void btnBack_Clickobject sender, EventArgs e{if
tabControl1.SelectedTab.Text == "Discharge"{tabControl1.SelectedTab
= tbOperation;}else if tabControl1.SelectedTab.Text ==
"Operation"{tabControl1.SelectedTab = tbPatient; }}
Step 7: Now add the following code in the "Save" Button.
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
10/12
Step 8: Now run the application and insert the record in the
text boxes.
Now click the "Next" button.
Now click the "Next" button.
TECHNOLOGIES ANSWERS BLOGS VIDEOS INTERVIEWS BOOKS NEWS CHAPTERS
CAREER ADVICE JOBS
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
11/12
Now click the "Save" button.
Now you will see the results in the SQL Server tables.
RELATED ARTICLES
Naveed ZamanI have been working as a Senior Software Engineer
and database developer since 2003for an MNC. I visit many websites,
daily to update myself.Now I want to share myknowledge with others
to improve myself. I'... Read more
Rank200
425.4kReaders
BronzeMember
1Time
Ajax tab control using CSS Container Controls 4 :
TabControlCreate Dynamic Tabs using AJAX tab container& add
controls & read them dynamically?
Closable Tab Control in WPFVersatile Tab Using jQuery
cwTab - A Tab Control in C# Gradient Background Tab Custom
ControlCreate Tabs Using jQuery and CSS Animated Tabs Content Using
jQuery and CSSRounded Tab Menu Using jQuery and CSS
COMMENTS 3of3
-
4/13/2015 LearnTabControlUsingC#
http://www.csharpcorner.com/UploadFile/e881fb/learntabcontrolusingCSharp/
12/12
Hosted By CBeyond Cloud Services
2015 C# Corner. All contents are copyright of their authors.
Sep 18, 2014
631 4 0 0 0 Post Reply
This will be very helpful when I get further into my learning
process. This seems quiteadvanced but explained in a way where
those newer can understand. Thank you kindly.
David W
Feb 20, 2015
634 1 0 0 0 Post Reply
nice..
Rajesh Dwivedi
Feb 21, 2015
200 797 425.4k 0 0 Post Reply
thanks alot
Naveed Zaman
Follow Comments
Type your comment here and press Enter Key....
COMMENT USING
Facebooksocialplugin
AlsopostonFacebook PostingasNageshBoddeti Comment
Addacomment...
MVPs MOST VIEWED LEGENDS NOW PRIZES REVIEWS SURVEY
CERTIFICATIONS DOWNLOADS
CONTACT US PRIVACY POLICY TERMS & CONDITIONS SITEMAP REPORT
ABUSE
PHOTOS CODE SNIPPETS CONSULTING TRAINING STUDENTS MEMBERS MEDIA
KIT ABOUT US LINKS IDEAS