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.
Related
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
i have a form with a few controls on it, i have a panel with different controls on, That panel is above the form controls.
i have added new controls to the form and when i place the panel back over the form, the new controls are showing through the panel itself, but only the new one controls and not the "old" ones, if i copy and paste a control or add a new one it has the same effect.
i have looked in the designer.cs and the new controls are being added to the form and NOT to the panel itself.
this is weird and iv checked various properties but cannot immediately see the reason for this.
i have made MANY forms before and this is the 1st time this is happening.
one the note of controls, is there a way to change the default value of the labels "AutoSize" property from TRUE to FALSE; i'm using visual studio CE2015
any ideas on what to check? im really stumped by this one.
As mentioned in the comments, you need to check the z-order of your controls.
In the picture below you can see a form I created with two buttons and a panel as you were describing. Neither button is one the panel, however button 3 has a z-order that puts it on top, just as the panel is on top of button 2
If you right click on the controls you want to change the z-order of you see Bring to Front and Send to Back. Choose the appropriate option.
In a user control of mine I implement a tab control that should programmatically manage tab pages. I connected the tab control with a context menu strip with the menu items "Add", "Edit", "Delete" to respectively add a new tab page, edit or delete an existing one. Initially, the tab control does not have any tab pages, and in this case the context menu strip does not appear on right mouse click; if a tab page is there, the context menu strip works as required. At that, the context menu strip is attached to the tab control itself, not to any of the tab pages.
I find this state quite illogical, and my question is whether there is any possibility to make the context menu work attached to a tab control work even if the tab control is empty?
Empty TabControl does not receive mouse events. They are passed to the underlying control.
You can do the following.
Put the TabControl inside a Panel of the same size. Assign the same context menu to this Panel. Then, when TabControl is empty, mouse events will be passed to the Panel and menu will be shown too.
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).
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.