Winforms .NET TabControl - show some controls on each page

crandelj used Ask the Experts™
I have a standard TabControl on a Winforms VB.NET form.  The program is used for reporting, and a couple of controls like the DateTimePicker and a couple of textboxes I'd like to have display on EVERY tab page of the TabControl.  

I tried to figure out a way to do it from the designer but no luck.  Then I started digging through the solution to see if there is something the controls the visibility of the controls within a TabControl page.  No luck.

So, is there a way to have a control like DateTimePicker1 display on every page of the TabControl, in exactly the same place and the same way?  While still allowing me to have other controls on the individual pages that are different?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You could put the controls that you want on each tab on a windows form. Then place a copy of that form on each tab at runtime. This windows form can be created in the designer, but I think you'll have to put the form on the tabs at runtime.


I'm not sure if that would work.  I just tried to add a DateTimePicker control already on the first tab to the second tab.

Using this code:
            With TabOrders
            End With

And what happens is it moves the DateTimePicker1 control to the second tab and removes it from the first.  
So I think if I created a form like you suggested it would do the same thing.  But I could be wrong.

I think what I am trying to do is working against how the TabControl is designed to function.  I think was designed so that controls on each tab have to be unique to that tab.  But that is just a guess.

I might still try to create the new form as you suggested but that requires more significant changes to my code.  I'm wondering if there is a simple way or if this is just not a way the controls are meant to be used.
You cannot add the same instance of a control to multiple tabs, or even multiple forms. But you can create a single form (with initialization and extra functionality all in one place), and then add a new instance of it on each tab of the TabControl. It shouldn't be that big of a change, but I don't know your code.
Hello, crandelj,

If I understand what you want to do, my approach would be to simply put the "common" controls (i.e. DateTimePicker and TextBox controls) directly on the form, not on the TabControl.

You can position them above the TabControl in the positions that you want.

To ensure they sit above the TabControl, just use the Designer's Format menu.  Select the TabConrol, then click the "Format+Order+Send to Back" menu command.

If you need to have them move around or appear and disappear as the TabControl moves or changes visibility you can use appropriate TabControl event handlers for this.



That worked easily.  Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial