Hey. Does anybody know how to change Form designe on button click in the same Form, but not by opening new one.
Sorry for my English.

Recommended Answers

All 6 Replies

Do you mean as in move objects around on button click?

I'm crating Login system right now. And i whant to make all user panel in 1 Form. So I need to make somehow that on login button click the all designe of the form change to like: Welcom "username", and then display all the user information in the same form.

Well I've personally done that before by laying out all the components of both parts and then controlling what is visible at load and then after button press to show/hide bits. However there may be a tidier option.

Mikey's way will work (I've done it before myself) but like he said it can get messy. If you're doing it that way make sure you start the name of all your objects with the type of layout you want (e.g. adminFirstNameTextBox for admin view or say userFirstNameTextBox for a generic user).

Another way is to make use of the Component object but having one form but multiple Components that just sit on top of the form. This way only the relevant component needs to be displayed dependent on the type of user, rather than having to keep making objects visible and invisible.

As well as being a bit tidier by seperating the controles for the different useres, it would add a bit of structure to your program and make editing the controles for the different types of users a lot easier (Users will more than likely want to add or remove object like textBoxes... trust me it comes from experience).

I've also done something with tab controls before and hooking into the draw at run time to hide the actual tabs showing, then programatically hopping between the two. Would need to google to find it again though.

commented: I've not done it myself but I've seen it done +4

I've also done something with tab controls before and hooking into the draw at run time to hide the actual tabs showing, then programatically hopping between the two

This works well if you want to keep all the controls and their handlers under one form.

The method I use is to set the DrawMode to OwnerDrawn fixed, Appearance to "Buttons" and the ItemSize to (5,5).

This allows you to click on the the buttons to change Tabs while in the designer and does not take away much design space.

The wrinkle that I throw in is to place a docked panel as the first control on each tab. Then all other controls are parented to that panel.

The tabcontrol is parented in a panel on the form during design. I set tabcontrol's Parent property to null on loading the form. This leaves it fully functional just hidden and out of the way.

I then play a Parent swap game with each TabPage's first control (the panel mentioned above) by setting it's Parent property to the panel that originally parented the tabcontrol. I use the SelectedTab property to keep track of whick panel is currently parented to the form.

commented: Another good implementation +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.