Search KB Filter article types
Form Concepts CodeSample - UserControls on Tabs
Categories: UserControls, UserControls Switching
Tags: Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
Revision: 1
Posted: 20/Sep/2009
Updated: 23/July/2010
Status: Publish
Types: Code

This article will have a few sections added to it soon, based on the following article type skeleton: CodeSample
Overview

This article is a part of Form Concepts series of articles.

The codesample shows how you use a TabControl for navigation and dynamically create and remove tabs from the TabControl. Each time a new TabPage is created, a new UserControl is dynamically created and added to the tab. For the purpose of simplicity, the same UserControl is added to each new TabPage,  but in real life applications you would probably have different UserControl on each tab.

This method for navigation is one of two similar ones where you use dynamically created UserControls instead of Forms. The other method can be found in Simulating IFRAMEs codesample.

VB.NET Code
Imports Gizmox.WebGui.Forms
Public Class TabForm
    Friend WithEvents Panel1 As Gizmox.WebGui.Forms.Panel
    Friend WithEvents btnAddTab As Gizmox.WebGui.Forms.Button
    Friend WithEvents TabControl1 As Gizmox.WebGui.Forms.TabControl
    Friend WithEvents btnRemoveFirstTab As Gizmox.WebGui.Forms.Button
    Dim TabCounter As Integer = 0
 
    Sub New()
 
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        Me.Panel1 = New Gizmox.WebGui.Forms.Panel
        Me.btnAddTab = New Gizmox.WebGui.Forms.Button
        Me.TabControl1 = New Gizmox.WebGui.Forms.TabControl
        Me.btnRemoveFirstTab = New Gizmox.WebGui.Forms.Button
        '
        'Panel1
        '
        Me.Panel1.Anchor = Gizmox.WebGui.Forms.AnchorStyles.None
        Me.Panel1.BorderStyle = Gizmox.WebGui.Forms.BorderStyle.Clear
        Me.Panel1.Controls.Add(Me.btnRemoveFirstTab)
        Me.Panel1.Controls.Add(Me.btnAddTab)
        Me.Panel1.Dock = Gizmox.WebGui.Forms.DockStyle.Top
        Me.Panel1.Location = New System.Drawing.Point(0, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(727, 97)
        Me.Panel1.TabIndex = 0
        '
        'btnAddTab
        '
        Me.btnAddTab.Anchor = Gizmox.WebGui.Forms.AnchorStyles.None
        Me.btnAddTab.Dock = Gizmox.WebGui.Forms.DockStyle.Left
        Me.btnAddTab.Location = New System.Drawing.Point(0, 0)
        Me.btnAddTab.Name = "btnAddTab"
        Me.btnAddTab.Size = New System.Drawing.Size(119, 33)
        Me.btnAddTab.TabIndex = 0
        Me.btnAddTab.Text = "Add new tab"
        '
        'TabControl1
        '
        Me.TabControl1.Anchor = Gizmox.WebGui.Forms.AnchorStyles.None
        Me.TabControl1.Dock = Gizmox.WebGui.Forms.DockStyle.Fill
        Me.TabControl1.Location = New System.Drawing.Point(0, 33)
        Me.TabControl1.Multiline = False
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(727, 413)
        Me.TabControl1.TabIndex = 1
        '
        'btnRemoveFirstTab
        '
        Me.btnRemoveFirstTab.Anchor = Gizmox.WebGui.Forms.AnchorStyles.None
        Me.btnRemoveFirstTab.Dock = Gizmox.WebGui.Forms.DockStyle.Left
        Me.btnRemoveFirstTab.Location = New System.Drawing.Point(119, 0)
        Me.btnRemoveFirstTab.Name = "btnRemoveFirstTab"
        Me.btnRemoveFirstTab.Size = New System.Drawing.Size(125, 33)
        Me.btnRemoveFirstTab.TabIndex = 1
        Me.btnRemoveFirstTab.Text = "Remove first tab"
        '
        'TabForm
        '
        Me.Controls.Add(Me.TabControl1)
        Me.Controls.Add(Me.Panel1)
        Me.Size = New System.Drawing.Size(727, 446)
        Me.Text = "TabForm"
 
    End Sub
 
    Private Sub btnAddTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTab.Click
        TabCounter += 1
 
        Dim tp As TabPage = New TabPage
        tp.Text = "TabPage" + TabCounter.ToString()
 
        Dim u As UC = New UC
        u.Dock = DockStyle.Fill
        u.lblCounter.Text = "Usercontrol number " + TabCounter.ToString()
        tp.Controls.Add(u)
 
        Me.TabControl1.Controls.Add(tp)
        Me.TabControl1.SelectedItem = tp
    End Sub
 
    Private Sub btnRemoveFirstTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveFirstTab.Click
        If TabControl1.TabPages.Count > 0 Then
            TabControl1.Controls.Remove(TabControl1.TabPages(0))
        End If
        If TabControl1.TabPages.Count > 0 Then
            TabControl1.SelectedItem = TabControl1.TabPages(0)
        End If
    End Sub
End Clas


C# Code
The conversion of this code to C# has not been completed yet.


About the author

Related Articles

UserControls  
Title Update Author
This video demonstrates how to work with user controls.
Tags: Developers, Drag & Drop, 1. Beginner, 2. Intermediate, 3. Advanced, Customization, Layouting, Pre v6.3, v6.3, v6.4 and Later
01/Jan/2009    2009/01/01
This sample application was created on VWG v6.3.x. The creator of this application suggests that VWG v6.4 would give much greater flexibility.
Tags: Architects, Developers, Events, Resource Handlers, VB.NET, 2. Intermediate, 3. Advanced, Customization, Layouting, Pre v6.3, v6.3
07/Jan/2009    2009/01/07
Tags: Architects, Developers, Data Binding, 2. Intermediate, 3. Advanced, Data Binding, Pre v6.3, v6.3, v6.4 and Later
02/Jan/2009    2009/01/02
This sample code demonstrates working with user controls to simulate frames
Tags: Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
12/Jan/2007    2007/01/12
Tags: Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
08/Aug/2010    2010/08/08
Tags: Developers, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
21/July/2010    2010/07/21
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS