Solved

Showing a Form as a child of a Tab seamlessly

Posted on 2007-04-03
13
223 Views
Last Modified: 2010-04-23
I am trying to migrate a VB6 project coded by somebody else into VB.NET.

The VB6 project contains a form that has many frames with many controls: total controls in the form around 200.

I want to create a separate Form for each VB6 frame in the new VB.NET project, to make the project more manageable.

But in the UI, I dont want the user to know that he is dealing with separate forms. In the main form, I want to have a tabbed interface, and when the user clicks on the Tab, I want to load the respective Form into that Tab and show it as a child of the Tab.

Is it possible ? Is this approach good ? Pls. give your suggestions. Which control can give me a tabbed interface in .NET ?
0
Comment
Question by:rajesh_khater
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18842773
Sounds like what you really want is a user control for each tab. This will allow you to create a layout that can be compiled and dragged onto your tab in the designer, just as you desire.

The biggest difference will be that you don't have all of the extra overhead items that come with the form (the maximize, minimize and close buttons for example)

If you're using VS2005, there's a "TabControl" control that should help with the layout.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 18843558
You can make the forms borderless and set their Dock property to Fill when you place them into the TabControl to make them "seamless"...

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fa As New FormA
        ' initialize "fa" if needed...
        AddFormToTabControl(TabControl1, fa)
    End Sub

    Private Sub AddFormToTabControl(ByVal tb As TabControl, ByVal frm As Form)
        Dim tp As New TabPage
        tp.Text = "Tab" & tb.TabPages.Count + 1

        frm.TopLevel = False
        frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        frm.Dock = DockStyle.Fill
        tp.Controls.Add(frm)
        frm.Show()

        tb.TabPages.Add(tp)
    End Sub

End Class
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18843584
Now, Bob.... you don't really expect to get points for the same code in both questions from the same poster??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 18843603
Hi rajesh_khater;

This will show a form inside a tab page of a tab control seamlessly, without any frame border.

        Dim newFrm As New NewForm
        newFrm.TopLevel = False
        newFrm.Parent = TabPage1
        newFrm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        newFrm.WindowState = FormWindowState.Maximized
        newFrm.Show()

Fernando
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18843621
G'morning Chaosian!

It's Mike by the way.  Bob is "TheLearnedOne".  =)

I know there are two questions.  I have posted in both as I don't know which one will be deleted...this one is technically "older".
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 18843654
Yeah... as soon as I saw the notification, I realized it wasn't TheLearnedOne posting... too fast on the trigger, I guess. Sorry 'bout that.
0
 
LVL 1

Author Comment

by:rajesh_khater
ID: 18843890
I have not abandoned this question.
The other question is more specific. This question is more broad.

Anyway, if you want, pls. reduce the points of each to 250.
0
 
LVL 1

Author Comment

by:rajesh_khater
ID: 18843922
Is this a good approach ? That is, showing a form inside a tabcontrol. I am doing this to break one large form into several medium-sized manageable forms, but to give the illusion of a single form to the user .
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18844010
I don't see a problem with it...

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18844090
There is not technical reason why you can't do this and it does solve your need.
0
 
LVL 1

Author Comment

by:rajesh_khater
ID: 18853083
What about common event handlers for controls in different forms ?

Earlier in one large monolithic form, I could write a common event handler. Is it possible for several controls spread across multiple forms too ?

And passing variables to and fro between forms.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18853120
Sure it's possible...you can use AddHandler() to wire up controls with common event handlers.

Pass across forms is also possible...you just need to pass references to the forms amongst each other or make the forms raise events that the main form captures and passes on to the other forms.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question