VB.Net - User interface

Wespen

Newcomer
Joined
Jan 13, 2003
Messages
10
Hi,

I have a treeview on form (left) and by changing node a different options should show on right. (Something like computer management console)

Is there any way to design "sub forms" on right without drawing them trough code?

A workaround I used is tabcontrol with hidden tabs.
I know it's a bit "lazy beginner" workaround.

Do you know any better way??

Thanks
 
There isn't really a better way. Personally I use panel controls to host all the different child controls, and hide and show the panel controls as needed. If you attach a panel control to the .Tag of a treenode you can pretty much automate the process too.
 
Got Any Examples?

If you attach a panel control to the .Tag of a treenode you can pretty much automate the process too

Fascinating! Divil, can y0ou provide an example or two of automating that process? I would love to be able to do that with treenodes...
 
Well, when you create the node you'd set it's tag property, like so:

Visual Basic:
Dim d As New TreeNode("blah")
d.Tag = Panel1
myTreeView.Nodes.Add(d)

Then, in the AfterSelect event of the treeview, you'd have to run a loop to hide all visible panel controls on the form, and then show the control associated with the selected node:

Visual Basic:
Dim c As Control

For Each c In Controls
  If typeof c Is Panel Then c.Hide()
Next

DirectCast(e.Node.Tag, Panel).Show()

I made that up on the spot and haven't tested it, but something like that should work.
 
Someone pointed me to a free tab control at www.dotnetmagic.com. This control is better than the standard Windows tab control because you can disable the tab part (the little part that sticks up above the tab page that has some text and possibly an icon) but keep the tab page. Each tab page acts as a container to other objects. You can easily populate each tab page of the control during design mode, switching between tabs as you are designing. Then, you can hide the tabs in run mode and switch between tab pages programatically. There is no need to jack with the visible property of individual controls because only the controls on the active tab page are shown. It is just a matter of setting the "activetab" property (I can't remember what the actual property name is, but it is pretty intuitive) to change the page.
 
I mentioned a few other possible unwanted side effects to using a 3rd party control, such as dotnetmagic, in this thread.

If you don't need the benefits of the control, it's probably better to stick with Panels or a regular tab control. But maybe the dotnetmagic version does some other things he'd like. I like presenting options :)

-Nerseus
 
Makes since guys...

The thing about 3rd party "anything", be it a Nintendo controller, memory pack or Microsoft Windows controls; the 3rd party thingy may work just fine, but it may also have errors or problems with it just with normal operation...

Of course, if it doesn't then you're rock'in but if it does then it may more of a headache than a solution...Try it, never know till ya do...

As a general rule of thumb for me, I'm in agreement with Divil and Nerseus on the subject...

What would probably make life much easier is if you used Divil's code above but with a slight modification where instead of showing and hiding panels, just create all of the panels and put them in the exact same location as well as make them all the exact same size...

Now you can use the .BringToFront() method as your users click on the nodes...This way you wont have to worry about hiding anything nor checking it's visible properties ;)
 
If you keep them all visible, I think it's more resource intensive than hiding the unused ones. I think windows may still be doing something "extra" behind the scenes as far as processing windows messages. I'm not sure, but it's a guess.

As for 3rd party controls, it might be a good idea to see what the company offers in terms of source code. We use controls from DevExpress and they give us FULL C# source code for ALL the controls. Other companies use a repository of sorts that holds the source code in the event they go out of business. By paying a bit extra for the controls, you will get the source code if the company ever goes out of business. This is a nice feature if you're worried about fly-by-night companies and you really don't want to get stuck in a project two years from now with a bug in a 3rd party control...

-Nerseus
 
Back
Top