How to add multiple tabs or pages in Win forms Application - c#

This is UI of the app which I'm creating, So if a user clicks Home button he should be able to play with some specific controls and again if he presses Sellers button, new tools and controls should be visible on the screen!
I tried to implement this by using 4 panels with
panel_name.visible=false
in respective button click event, but the problem is each panel should take up 1/4th of the space in the form to display all of its respective tools.This makes the panel area too small!
How can I make the application such that If a user clicks Home button, he should see one page/tab and different tabs/pages for different buttons clicks?

I suggest you use the user controls: right click on your solution> add> user control
C# UserControl
How to create and use UserControl
The user controls are similar to the forms, since you can place controls on them, the difference is that instead of showing them as common forms, you drag them as a control inside the form

Related

Tab Order With Selected Area

During Design Time of a Windows Form there are a lot of controls to assign their Tab Order with VS Tab Order Button automatically (by clicking each control sequantially).
Is there a way to select a Specific Area in form (contaning limited count of controls to be tab ordered).
Otherwise Tab Order button selects all controls in the form (Labels have no Tab Order although) and it is very diffucult to see clearly related control to click.
No the designer doesn't have such feature, however, if you have such requirement, you can create some user controls and then setup the tab indexes in designer of each user control.
This way you decide about the tab indexes of the user control in the designer of the user control and the tab indexes of the user controls will be part of the user control definition and will be reused in different forms.
Also since the user control is a container control, at the designer of the form, you need to just specify the tab index for the user controls. Also you will see less controls to assign tab index.

Buttons changing Tabs

I want to make buttons change Tabs but i want the tabcontrol to be invisible (Only the page visible not the tabcontrol buttons).
I have 2 buttons Home and Settings and when the Form starts the Home page is visible and when the user clicks Settings button it changes to the Settings page and the same goes for Home button.
So what i need is for the Home and Settings tab buttons to be invisible and i want to only be able to use the buttons i created to change the pages. Hope someone understands. I use Visual Studio 2015 and C#.
Going by the name of your control (TabControl1) I am assuming this is WinForms.
You can achieve what you are describing without using a tab control at all, just move the contents of each of your tabs to seperate UserControls and then swap the visibility or positioning (or both) upon each button click.
For Home button click handler:
settingsUserControl.Visible = false;
homeUserControl.Visible = true;
Then repeat the reverse, in the Settings button click handler.
If you are using TabControl for its border, then use a Panel as a container to the UserControls.
In fact, this is similar to how Tab Controls worked in VB6, the control being hidden would be shoved 30,000 Twips off to the left, outside the view port of the tab control.

winforms panels as slides?

I have one Form1 in Windows Forms and want to show and hide different sets of controls, depending on which button the user clicks. As you find it for example in many option dialogs, categories on the left-hand site, the actual config options on the right-hand side. And I don't want to use tabs for this. What's the control I need?
Here's how to do it:
Add a panel control to the right side and dock it as Fill
Create user controls that will fit within the panel control. These user controls should contain the different groupings of controls that you want to display.
When the event happens on the left side (e.g. someone clicks a button or tree item), dynamically load a particular user control on the right side as shown here:
while (Panel1.Controls.Count > 0) Panel1.Controls[0].Dispose();
Panel1.Controls.Add(new MyUserControl());
You can then create a variable that casts Panel1.Controls(0) to your actual control type and work with it however you want:
MyUserControl myControl = (MyUserControl)Panel1.controls(0);
You will likely want to change Panel1.Controls(0).Dock to style Fill as well.

Change panels / views based on button click

I would like to implement the following WinForms user-interface, with two buttons at the top that allows the user to toggle between two views.
So, when I click the 1st button ("Show User Profiles"), the three panels below should show the three different user profiles (with some content fetched from database), like so...
And when I click the 2nd button ("Show Chat History"), the three panels below should show the three different chat histories (with some content fetched from database), like so...
What is a good approach (either dynamic or static) to implement this kind of structure in C# / .Net? Is there a cleaner or at least more efficient way than my crude method below:
Layout three sets of controls for the three Profiles
Layout three sets of controls for the three Chat-Histories, overlapping on top of
the Profiles' controls.
Change visibility of the controls based on which button is pressed.
For example, if 1st button is clicked, Set Visibility=false for all the controls related to Chat-History, and Set Visibility=true for all the controls related to User-Profiles.
a tab control would give you a separate set of panels. Its the obvious way to do it, but if you want to overlay panels and control the visibility you can, and its fine. I have a content viewer that displays either images or text depending on the mime type of the content, and that context switching occurs without user interaction, so it makes sense there to put the image control on top of the textbox and set it visible if the mime type is image/jpeg. Where a user is going to make the choice tho, I would use a tab control.
I assume you are using the visual ui to add controls. you can just drag a tab control to your form and it should by default appear with 2 tabs defined. You can add more in properties my modifying the tabpages collection. That's where you would also rename them to reflect your choices (profiles, chats). drag the tab control up where you want it on the form and size it appropriately, or dock it to fill the form. drag 3 panels into the first tab, then click on the 2nd tab, and drag 3 more in there. then proceed as you would have. When the user clicks on the chat tab the tab control will manage the view - hiding the first tab and its 3 panels. Of course clicking the first tab would make that tabPage visible again. no need for you to code anything.
I'll just add that I don't understand the design of having 3 profiles visible, and 3 chat history's. Unless your users are going to be limited to 3 friends. I would think you would be better off using a listbox for friends names on the profiles page, with a single profile panel that just filled the profile controls based on which friend is selected, and then the same list on the chat page, with a single chat panel that loaded the history into the textbox based on which friend was selected. That way you can have all the friends you want :)
and for completeness i'll suggest one more way, why should the user have to switch between tabs to view a users profile or chat history when you can provide them both in a single tabPage? You could programmatically create a new tab for each user and on that tab have their profile panel on the left, and their chat history on the right. Less context switching = better user experience. The tab control will allow you to scroll for tabs that don't fit on the form automagically(tm).

How to load a new layout in C# when a button is pressed?

I want to load a new layout (just like we do in Android programming as layout1.loadLayout()) in C# when a button is pressed?
How can this action take place when a method is called?
If I am not clear in my question, I am looking to load a new set of controls and hiding the current controls temporarily on a window form when a button is clicked (while they should retain their current properties, so that if I go back they should be in the same way where I left them).
How can I jump between different layouts while not completely deleting and creating them again and again?
if this is for a desktop app, look into user controls.
info here
You could create panels to group controls and toggle it's visibility.
Look for panel control in components, then add controls to it, toogle it's visibility.

Categories