Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Using a TabControl in Visual Basic.Net

Author: Faraz
Download Source Code : 228_Tab Control.zip

In this article I will try to explain the technique of creating a TabControl for the Windows Application. Here I will discuss its properties by developing a small Windows Application.

You want to develop a windows application that contains all window forms on a single interface named as MDIs (Multi Document Interface). In .Net you will find a TabControl and TabPage classes that are helpful in developing and managing these kinds of applications.

 

TabControl occupies the area within the hashed border. It manages the TabPage objects through its TabPages collection property. You can add pages by selecting TabPages collection property either from the property browser or by right clicking on the Tab Control and selecting the “Add Tab” option. Each Tab page has its own properties by using these properties you can format these pages. For example, you want to name the Tab then using the Text property you can set its name and these properties can be accessed by selecting the TabPage Collection property from the property browser.

 

Once you have added the control you can place controls onto the pages just like you place them on the form. Using the Tab Control Appearance property you can display the Tabs either like buttons or flat buttons.

 

Now, consider the following application that contains the two TabPages. Using these pages I have developed a simple application that reads comments from the first TabPage and shows it onto the next TabPage on the button click event. 

 

To create this application first of all Add the TabControl on the windows form. Name the TabControl as “tctrlTest”. Select the TabPage collection property and add the Two TabPages in the TabControl named these pages as “tpRead” and “tpShow”. Set their Text property to “Read Message” and “Show Message” respectively. On the both TabPages add the TextBox control, set their name to “txtGetMessage” and “txtDisplay” respectively. Set their MultiLine property to “True”. Finally, add the button control on the “tpRead” TabPage, name this control as “cmdShow” an set its text to “Show on Show Message”.

 

Add the following code in OnClick event:

 

Private Sub cmdShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdShow.Click

Me.txtDisplay.Text = Me.txtGetMessage.Text

Me.tctrlTest.SelectedIndex = 1

End Sub

 

In this code the text of “txtDisplay” is set equal to “txtGetMessage”. After setting the text the Tab’s SelectIndex property is set to “1”. This means that the “Show Message” TabPage is selected. Run the application and see its output.

Article Comments
Hey, i was looking for it, on the other source codes i could not see especially the usage of selectedindex property :) So now i am going on my works. Thank you very much for this code.


Grazie :)

Posted on 7/5/2006 11:30:12 AM by tevfik

hi, i m having another problem
i want to hide a tab page on click of a button Please help me

Posted on 12/27/2007 6:26:13 AM by Neetu Maheshwari

hello i have a problem. i want to show a specific tab page of another form by just click a button please help me with the code.and thank u

Posted on 11/10/2009 9:37:07 AM by matias

Hi Matias,

You can use tabs index to do this as we work with array same like that...explorer attached source of article.

Thanks.

Posted on 11/10/2009 9:44:44 AM by zunnair

Hi,
How can I Save all the information in the tabs, I can Save it from the form but I don't know how to do it from the tabs.


thanks.

Posted on 11/16/2009 12:13:36 AM by Javiel

Hi Javiel,

You can save data from tab same as forms, you can create buttons on tabs and here you can access its all fields same as simple form.

If you are facing an other issue then let me know.

Thanks.

Posted on 11/16/2009 3:34:11 AM by zunnair

Thankyou sooooooo much...

Posted on 2/7/2010 7:44:23 AM by Akee

I'm having a really strange problem w/vb 2008 express when adding objects to any tab page other than the first. When I add to the second, for example, it passes back to the first.

I'd appreciate any guidance.

Posted on 2/8/2010 7:46:16 AM by Charles

Nice. Concise and it works. Thank you very much.

Posted on 2/22/2010 5:36:33 AM by David

Hi i have a problem. If i put label box in tabscript. the label box is in back of tab. i dont know how to put labelbox in front of tab. please e mail me.. blockcircuit_3@yahoo.com

Posted on 3/14/2010 10:51:50 PM by Problem

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Multithreading in VB.NET, A Beginner’s Guide

Disclaimer - Privacy
© 2002-2017 DevASP.net