Best Practice? Same control/different tabs or unique controls for each tab?

StillLearning

Member
Joined
Dec 21, 2012
Messages
12
Programming Experience
Beginner
Hey awesome folks!

I know I CAN do it either way. I have a public button, "ButtonExit" which I can "re-use" by adding it to the selected tab on the MyTabControl.SelectedIndexChanged event.

Interestingly, it is automatically removed from the original tab so I just add it back when that tab is re-selected.

VB.NET:
tlp1.Controls.Add(ButtonExit, 0, 0)

tlp2.Controls.Add(ButtonExit, 0,0) 'etc.

'my ButtonExit is actually in a TableLayoutPanel(tlp1 for tab1, tlp2 for tab2, etc) which I think is irrelevant, but you never know...

Is there some reason not to be moving controls around? Is there some reason this is a good practice, and thus I should I just create a different ButtonExit control for each tab?

I can go from tab to tab to tab and the EventHandler never loses that ButtonExit's presence...

Thank you!!
 
Hi,

I am assuming that this Exit button is to close a form as apposed to closing an individual tab page? If so, then I would think that this is more a matter of Preference over Best Practice. As I can see it there are three other options open to you:-

1) Remove the need of coding the movement of the Exit button in the SelectedIndexChanged event by adding an Exit button to each of the tabs and then just ensuring that each button uses the same event handler to exit the form.

2) Find some space outside of the Tab control to place the Exit button once only.

3) Get rid of the Exit button all together and just use the forms Close button in the ControlBox at the top right of the form.

Hope that helps.

Cheers,

Ian
 
You should have one and only one Button and you should not be moving it anywhere. The Button's Parent should be the form, not any TabPage. The Button should visually be on the form rather than any TabPage also, as per IanRyder's option 2. If you are determined to have the Button appear visually on each TabPage rather than on the form then it should still be parented by the form. You simply change its Location in the Properties window so it sits on top of the TabControl. You can use the Bring To Front option on the Button or the Send To Back option on the TabControl if required to ensure that the Button is visible and not hidden by the TabControl.
 
Thank you for the response!! I suspected, I might get a "talking-to" about Form design and the necessity of re-using a ButtonExit control. I am grateful for your guidance.

I was trying to keep the question generic, but the more detailed explanation is that I have a Horizontal SplitterContainer (with a TableLayoutPanel in Panel1(2 columns), and a TableLayout Panel in Panel2(1 column) with various buttons and a DataGridView at the very bottom with a BindingNavigator on top of it. There are buttons, etc. which are common to 3 of my 6 tabs. All of this is under a MenuStrip and a ToolStrip which is common to all 6 tabs (docked to the top of the form).

It's very convenient, because all I have to do is add that SplitterContainer to the user-selected tab on the TabControl.SelectedIndexChanged event and EVERYTHING inside it goes with it!! Very cool, and I send the DGV through a -reconfig sub to add/remove columns as appropriate for the selected tab...

I have yet to use the "Visual" part of Visual Studio... I just figured I'd learn more doing it in code, and this part was relatively easy compared to other things I have overcome... (Picture: Ever seen a monkey try to fornicate with a football or solve a Rubik's Cube??)

Again, I am grateful for your guidance. I have tried to avoid asking questions I can find the answers to on Google. I was worried perhaps there was something others have learned the hard way about re-using controls that I couldn't find on Google.
 
Last edited:

Latest posts

Back
Top