C# custom GUI, better implementation? - c#

I'm making a custom GUI for my application. Basically my application has multiple 'tabs'. Each tab has a panel control binded to it, to display tabs contents. Whenever any of the tabs are clicked, appropriate panel control becomes visible (that displays contents) and the rest of the panels become invisible.
The problem is that when I design them in Visual Studio, it's hard to work, ether panels are stacked up on each other or I put them in different coordinates, and when panel becomes active, it's location is updated.
Is there I way I could design all the panels, like on separate 'form' or something like the same way I have separate classes? if that makes sense. Thanks!
EDIT:
I can't use the standard tab control, because my application has custom GUI, all buttons and everything is designed in image processing app. Tab control doesn't allow me to use my own graphics.
I'm going to take a look at UserControl, thanks everybody!

You can create each tab content in a separate UserControl. Use that each UserControl as the only content on each tab.

You should be able to design each "panel" as a separate UserControl.
Your main Form can just be composed from those UserControls, instead of having the entire UI built into one class.

First I would suggest you stick with the standard .NET controls in most cases. Particularly in this case the standard TabControl seems to be a good fit.
That said, you can place all the panels on the form in their final location (being sure not to place a panel within the other panel). You can then use the drop down in the Properties dialog to select the Panel you wish to work with. Next go to the Format menu and choose Order->Bring to Front. This will bring the wanted panel to the front so you may use the designer on it. You can then continue to hide or show the appropriate panels at runtime.

Related

A process on a single win form window

I am developing an application in Windows Form C#, it begins with an explanatory window, language selection and a start button when the desired language is selected, I want that when I press the start button, all the elements disappear and begin the application process, I had thought of creating a new form, but this opens a new window and I don't want that, I want everything to happen on a window. Apart from making all the previous controls invisible, is there any way to achieve this? Or maybe a way to make all the controls invisible without going one by one?
You could put multiple controls in a panel for example and hide/show entire panel.
If you dont want to do that, you could always do it in a loop
for example:
foreach ( var control in this.Controls)
{
control.Visible=false;
}
Ofcourse you could also add controls dynamically, but that might be hard for a beginner.
You could also make use of MDI forms, but that might be also not worth it.
SOLVED
Solved using user controls, user controls allow me to design the application interface in the same way as a form and I can add and remove that control from the form as many times as I want, making it possible to display numerous interfaces in a single Windows Forms window.
This solution was suggested by Jeroen van Langen in the comments of my question and it was exactly what I was looking for.

Navigating between parental panels

I have problems with editing panels in C# windows forms(Visual studio 2008). I placed some panels into another, and now I have problems with navigating panels inside parental containers. Is there any tool that gives not only drag-drop control, but also tree view of container and panels in it. For example, like Navigator window in NetBeans(IDE for Java). Any help?
I'm not sure about VS2008, but newer versions have Document Outline Window (View > Other Windows > Document Outline)
To not get lost in controls, consider to name them properly. Then you can find them in the list of Properties window.
Instead of label1 use labelInputName, located on panel1, which you also rename to panelInput. This gives parent/child feeling and you will never lost.
If you get lost, use Document Outline window to see tree-like relation via Controls property (who is control of who). This window is a helper (help to find and select control), you will still have to use designer to do changes.
Another important thing is UI design. Whenever you get cluttered or bulky feeling, than it's the time to change something.
Making UserControl for repeatable part is one way.
Another is to differ design and run time (what you see in designer): to example, if you have several panels, which has to be shown at same place, then you can use dynamic container for them (FlowLayoutPanel, TableLayoutPanel) or you can have them placed in a way for you to easily see them in design-time, but their position will be corrected during run-time (to example, in the constructor). Prioritizing designing is a must if you are going to support project and edit functionality in next versions.
p.s.: talking about winforms, but all said should be true for wpf as well.

WinForm with DevExpress NavBar Control and How to Change the Target Panel Correctly

I want to do this correctly instead of a hack, so help is appreciated
I am starting a very basic project, using a DevExpress NavBar control in a WinForms project, in C#. Easy enough.
NavBar is in the left part of a splitter, and I want the right part of the splitter to change based on what item you have clicked on in the nav bar. You know, one second its a grid, then next it's a calendar.
I could screw around with hiding and showing windows, but I know that's not right.
Just using a tabbed control seems real close, except I don't need the tabs, the nav bar is where the user picks what he wants to see.
So would I use panels in some way? Some type of modified tab control? Do i just pile on top of one another my various pages of controls for each nav option? So many pieces, doesn't seem to be any clear documentation on how to accomplish this very simple problem... after an hour of digging, thought I would ask.
Thanks.
So would I use panels in some way? Some type of modified tab control?
You can use tab control in other way. Just hide the XtraTabControl headers via the XtraTabControl.ShowTabHeaders option.
You can create a user control for each view that a NavBar button would invoke. When the user clicks the button you dynamically generate that view and add to the right part of the splitter. What ever user control was there before you dispose of.
This will keep your app very light when executing and make it composable.

What is a Tab Control?

In the most basic sense, what is a Tab Control?
I am looking into creating one from scratch (I have many good reasons for this and simply extending existing ones won't make me feel better). But I am not sure how they are made.
Is a Tab Control just a bunch of Panels, inside a main Panel? Here's a picture of what I mean...
At it's core, TabControl is a very simple control. Nothing but a row of rectangles with text on them. It is Winforms that adds the TabPage class, a scrollable container control that adds the ability to hide controls. Derived from the Panel class.
It bulks up with features that you can arbitrarily drop. Like rendering in a way that's compatible with the active visual styles theme that the user selected. And dealing with an app that asks for more tabs than can fit in a row. And implementing both keyboard and mouse navigation. And implementing transparency so the parent window content is visible behind the tabs.
It is so simple that the need to implement your own is rare :)

C#: Move Controls From Form to tabPage in VS Form Designer

I decided to change a utility I'm working on to use a tabpage. When I tried to drag various controls from the form to a tab page on top of the form, it made copies of the control, giving it a different name. It's easy enough to just remake the form on top of the tab or just edit the source code in the designer to have everything be added to the tab instead (and this is what I did, which worked), but it seems like there would probably be a better way to do this via the gui.
The correct tool for this is the Document Outline (CTRL+W, U). Simply drag your set of controls in the outline so that they are under the tab page. Voila.
The document outline dramatically simplifies these types of operations, especially when you are dealing with complex layouts.
Have you tried cut and paste. That usually works for me.
Your control key is stuck. Do not press control key when dragging controls.
I drag controls from form control to tab page controls all the time no problem. Answer #1 is totally correct.
You can use the Document Outline window and move the controls to the tab page one by one by dragging tree nodes.
The hardest problem is retaining control locations on the tab page.

Categories

Resources