Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

It has been 9 years since I have done some VB.NET development and I have never done anything with Tabbed form applications.
I ran into a problem when I wanted to copy a simple text box that was coupled to the MainForm Controls.Collection. As soon as I copied and pasted it, using the designer, Visual Studio linked it to the Controls.Collection of the visible tab page so it ended up something like this:
Me.TabPage1.Controls.Add(Me.lblConnecting)

But I needed it to be like this because I wanted it to be shown over any and all tab pages
Me.Controls.Add(Me.lblConnecting)

I found the first line of code in MainForm.designer.vb Then I did something you are not supposed to do: I changed and relocated it in that file to the MainForm controls collection and sure enough it worked.

OK: it worked but is there a more conventional way of doing this within the Visual Studio Designer?

Any answer/suggestion much appreciated.

What I have tried:

Use Google wide and far but no clear answers. Lots of information on how to manipulate the control.collections via code but not on how to do it using the designer itself.
Posted
Updated 28-Nov-19 3:41am

If you don't want the designer messing up your changes, you could move the lblConnecting to your code, e.g. after the form InitializeComponent().
 
Share this answer
 
Comments
fd9750 28-Nov-19 9:23am    
Yes, that would do the trick. I have done some testing and once InitializeComponent has executed the code actually ends up in the Form_VisibleChanged() function where I could add some code to correct any goofs caused by the designer.
It is a bit silly though to have to cure things like that. For the designer to be really functional it should support reassigning the Control.Collection it selected.
Hi,

I have found another silly method to solve it. Our application has to run on an 800x480 LCD touch screen so our MainForm and all the tabs are exactly that size.
I can make the designer copy the Text box and link it to the correct MainForm Control.Collection as follows:

- Open the application's designer.
- Select the main form in the properties window.
- Change the size to 1600x480.
- Copy the label/Text box I want to duplicate.
- Put my cursor in the empty extra MainForm area.
- Copy it there => it links the copied control to the correct Control.Collection.
- Select the copied control with the mouse.
- Move the control back in its desired position in the original 800x480 area (*).
- Reset the size of MainForm back to 800x480.

(*) Very important: only use the cursor keys on the keyboard to move the control, if the mouse is used to move it the designer will change the targeted Control.Collection as soon as you release the mouse button.

It really is a silly way of doing it but it works.
 
Share this answer
 
The only way to get the designer to know which container to drop the control in is to not have the mouse on the tab page when you drop the control. If the tab control is covering the entire form, you're going to have to resize the tab control smaller so you can see the form behind it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900