Show/Hide multiple TabControls at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Visual Studio 2003 C# Windows:

I have a tree view control as my main menu control down the left side of my
application. This has 2 Parent Nodes on it (Jobs and Employees). beneath
these 2 main functions I have 2 sub functions under each("Add Job", "View
Jobs" and "Add User", "View Users"). I have theses subfunctions grouped in a
TabControl, so there are 2 TabControl objects on my main screen, each with 2
pages on.

When the user first enters the application, all they can see is the Menu
Tree View. When they click a child node in the treeview, it reveals to them
the TabControl for the parent node of the one they selected, and changes the
TabPage to the relevant child node sub function.

My question is this:

Should I just be using the TabControl.Hide() and TabControl.Show() methods
to achieve this functionality i.e When they select a "Add User" I call
tcUsers.Show() then tcJobs.Hide(), and vice versa if they picked "Add Job"
OR
Should I destroy the current TabControl object, and then rebuild the
requested TabControl object??

If so, how do I do this destroy and create process?

Thanks

Steve
 
My suggestion to you is to use the "Visible" property to show or hide the tab
control. Setting Visible to "true" makes the tab control appear and setting
it to "false" makes the control disappear.
 
what is the beneift of visible over hide() and show(). My main concern with
doing it in this kind of way though was from a memory usage point, when you
hide or make an object not visible, does it stay in memory? Is this a point
worth worrying about?
 
You're right, the Show() and Hide() methods are inherited from the Control
base class. I never use those methods since they are equivalent to setting
the Visible property to true or false respectively and I've always used the
Visible property. To answer your question the control remains in memory when
you use the Hide() or Show() methods ( or set the Visibile property to true
or false ). I do not recommend destroying and re-creating objects when you
do not need to do so.
 
Back
Top