Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

Uhm... why would you want to? I could see removing one or more tabs, but why all of them?

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Sorry, didn't explain myself clearly :)

 

What I want to do is keep all the tab sheets but get rid of some of the little tabs above them. That way I can control what the user can interact with. For example i might not want them to be able to see certain tabs if they don't have admin privilages.

  • Moderators
Posted

you can do something like this...

   Private Sub ChangeControlsState(ByVal bState As Boolean) 
       Try
           Dim ctr As Control
           For Each ctr In tabClient.Controls
               If TypeOf ctr Is TextBox Then
                   ctr.Enabled = bState
               End If
           Next

           For Each ctr In tabLoan.Controls
               If TypeOf ctr Is TextBox Or TypeOf ctr Is ComboBox Or TypeOf ctr Is NumericUpDown Then
                   ctr.Enabled = bState
               End If
           Next
           btnApply.Enabled = bState
       Catch 'ignore errors
       End Try
   End Sub

Visit...Bassic Software
  • *Experts*
Posted

I think Robby is enabling/disabling controls, which isn't quite what RichDay was looking for.

 

Unfortunately, you can't disable a TabPage. You also can't set it to Visible=False. You have to actually remove it from the collection to which it belongs - the TabControl itself. Assuming you're defining your tabs in the Designer, your variable for each TabPage will exist Form-wide. Meaning, if you have code that needs to remove the tab and later add it, you'll always have a reference to the TabPage. This only matters if you had planned on creating your tabs in code using local variables rather than form-level variables.

 

Here's some code:

' Remove a tabpage named TabPage2 from the
' tab control TabControl1
TabControl1.Controls.Remove(TabPage2)

'Here's putting it back
TabControl1.Controls.Add(TabPage2)

 

Unfortunately, I don't know how to get the tab put back in any particular place. I've only had to do this once and there were only 3 tabs, so I did a Clear and then added them back in the order I wanted.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Gurus*
Posted

It's not unfortunate, it's just not the way the thing is supposed to work. Nowhere in Windows or any other app have I seen people either disabling tabs, or removing individual ones.

 

The tabbed dialog control is supposed to group together similar sets of controls, where they wouldn't all fit on to one form. Nothing more, nothing less. Bearing that in mind, you might want to re-think how your interface works.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • *Experts*
Posted

Removing tabs is fairly common - you just may not realize it's being done, depending on who you are. For instance, a file's property dialog box (right click any file in explorer and hit properties) may not show certain tabs like Sharing or Security if you don't have them enabled in your policy. I'm sure MS didn't write multiple versions of the dialog - they probably just removed the tabs that you didn't have access to.

 

As for disabling, I've never seen it done that I can think of. I did have one client that really wanted to have a tab look disabled. Luckily we talked them out of it. But some people have super-smart clients that want things done their way, regardless of standards. That, like not being able to disable a tab, is unfortunate :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • Moderators
Posted

What you can do is create the tabs at run-time, and only

create the needed controls when required. (user level and such)

 

The two methods I used above (removing tabs and disabling

controls) would most likely be used if the controls were all

created at design-time.

Visit...Bassic Software
Posted (edited)

I would create them dynamically but I have quite a lot of controls to put on the pages in a fairly complex layout so I'd rather do it in the designer.

 

Thanks for the pointer Nerseus, to get around it I might remove all of the tabs from the collection when the app starts and then add only the ones I want as required.

 

[edit]

Ok, that seems to work just fine, thanks very much. :)

 

One real life example of this: My app has a config form split up into sections (input/output files, storage directories etc...) with a tab control. I want developers for the interfaces my app exposes to have access to the raw config and setup files as well as the graphical config normal users see. It doesn't make much sense to hide this away in a separate window as the changes they make to the setup file impact on what is seen in the config window. This way they can save their changes and immediately see their effects.

[/edit]

Edited by RichDay
Posted
Howdy partner!

 

I thought you were being clever with you new dot net code. Now I know where you get your ideas.

 

:D :D

 

Ha ha, go away you stirrer ;)

  • *Experts*
Posted

You might be right, divil, but I like designing my tabs with Visual Studio. If you do all the design work by hand... well, it's tedious - unless you know another way than manually finding the right x/y coordinates for each control :)

 

About six months ago, I played around with trying to develop TabPages through a separate .cs file (inheriting from TabControl) but could never really get anything to work well. Ideally, a TabPage would be similar to a user control or a form and they could be designed completely independently of the TabControl they were contained in. But since .NET doesn't give us that, removing them from the collection is the best bet.

 

If you don't want to go through the trouble of creating the controls, you could design with the TabPages all added, then move out all of the code from InitializeComponent to a separate function before switching to Release mode. It's a bit more work to save a bit during runtime, but doable.

 

- Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
I had the same problem and found that you can't hide the tabs of a standard Windows tab control and just keep the panels. Someone pointed me to a free .net tab control at http://www.dotnetmagic.com. This is a very nice tab control that enables you to turn off the actual tabs (the little part that sticks up above the rest of the tab page) but keep the tab page itself. You can use each tab page of the control as a container for other objects, and switch between pages programatically. I have used this approach to create an Outlook-style UI. The main part of the screen is a dotnetmagic tab control without any tabs showing. I have an Outlook bar on the left, so when the user clicks various icons in the Outlook bar, it changes the active page of the tab control. It is way cool. Only complaint I have about this control is that if you do want to show the tabs, you can only have them at the top or the bottom of the control. You can't have them aligned vertically on either the left or right side of the control. For this, you have to use a standard Windows tab control.
  • *Experts*
Posted

Why not just use Divil's suggestion of multiple Panel controls and hide/show each one as needed? Carrying around a whole separate control is bound to take up more resources and means another file (at least one) to install. The only real disadvantage to using Panels is keeping them organized at design time and that can be overcome if you're careful in how you name and arrange them.

 

Another alternative, one I haven't used since VB3 so I don't know if it works, is to use the standard tab control but set it's top property (or it's location now) to something like -20 -- just enough so that the tabs don't show up but the whole tabpage does. If you're going to use a Tab Control of some sort, this may work better than the DotNetMagic version. Nothing against them (never seen it) but if you don't have to use a custom control it's generally better not to.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

So does tabMain.Controls.Clear() clear whole tab page or just the little top tab???

 

Another way to hide little tabs it to put tabcontrol in panel and move it to top to hide little tabs (so you can have it i the middle of the page)

 

And yes I can do that with hiding panels but its a nightmare in designer (especially if you have more than 10 panels :) )

 

Igor

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...