Different design time/Runtime WinForms control behaviour - c#

I am building an app that uses some built in and some 3rd party controls (DevExpress).
Inside the designer, everything looks OK, however while running the app, some controls are placed wrong.
Are there any easy ways to debug this issue?
More specifically, i have a container that holds 2 controls in it.
These controls should stack nicely together one on top of the other (indeed it looks like that in the Designer).
While running the app, one control is displayed on top of the other blocking it (see attached image).
Another weird thing is that some properties of the 2 controls that get overlapped are not updated with respect to their visual status.
this means that a control has a Location of (0, 300) but in fact appears to be in (0, 0).

As a workaround, you could place the two controls in the two panels of a SplitContainer and dock (fill) them there. This has also the advantage that the users can resize the controls.
Another alternative is the TableLayoutPanel.

Related

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.

how to re-use my windows forms in a dashboard that works like HTML frames?

My C# standard windows forms app is finished, it has 10 forms. But the new requirement is now to change the "multiple forms" to one dashboard where you click a link on a bar on the side or top and switch between forms in the main area of the dashboard one at a time, pretty much exactly the same way an old HTML frame works with framesets (just imagine my Windows Forms are framesets).
Without going into much detail, each of these forms are pretty involved, multiple threads and so on, and I am looking for a simple trick to display them, as oposed to recoding the entire thing.
I looked at http://www.codeproject.com/Articles/37397/A-Multipanel-Control-in-C
but it's not what I want.
Is there a way to do this?
If you convert the forms into custom controls, it then becomes pretty simple to use the TabControl http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.aspx to display the custom controls on the surfaces of the Tabs it contains.
By making them custom controls you avoid the mixing of the code for each of them (they remain distinct) but they also become easily added to other surfaces. I do this with a UI with a dozen display tabs.
I would recommend that you either use a tabbed control, or use an MDI Container, or a combination of both. The MDI has some nice behaviors that you'll get for free by implementing it. You could hard code each tab to each form, or have a dropdown that selects each view. If you want to manage the lifecycle of each form, you could implement a singleton pattern on each, or use IOC.
Not entirely sure this is going to solve your problem, but if you have questions or more details, let me know.
I resolved this using MDI as suggested above, works great in .NET Windows Forms 4.0 and 4.5.1.
In the parent form:
Declare a new child form.
myNewChildForm.MdiParent = this;
set child form StartPosition to Manual.
set child form Location to 0,0.
set child form WindowState to Maximized.
set child form Dock to Dockstyle.Fill
That does the trick.
Thank you all.

Winform: SplitterContainer inside a SplitterContainer misbehaves

I have a splittercontainer (vertical) placed on form. In the right panel, I placed another splittercontainer (horizontal).
When I run the application, the topmost splittercontainer works fine, no issues. The problem is with the embedded splittercontainer.
The size of the embedded splittercontainer when resized is fine, however the panels show up as a smaller size. I did not even thing that was possible. I cannot seem to get the embedded panel to consistently show the proper dimensions.
I did a search, and turned up this article.
http://support.microsoft.com/kb/953934
I tried out the recommended solution, and quite usual for any Microsoft post, it does not work.
In fact, things worked better without the suggested solution. At least after the application showed, I was able to get the panels to size properly, just by adjusting the splitter container of either control.
Thoughts?
Thanks in advance,
Sarah
After suffering for quite some time, it seems that posting my question got my head to think of a solution.
The outer splittercontainer must be set for docking type fill. Embed the second splitter container directly inside Panel 2 and have that set to docking type fill.
In the resize event, do not add any Controls.Add() for the splitter container, as that is done in the designer. You should add a Controls.Add() for any forms that you want to show.
Do not size the splittercontainers. Allow Windows to do that. Do resize the forms. Make sure to set the TopLevel to false first and show the form after adding to the control of the panel.
I tried the docking type none and several other things. It was either setting to none or setting the manually setting the sizing or whatever that caused the problem.
I hope this post helps someone.

Windows Forms Resizing And Overlapping UserControls

I have a Windows Form with 9 identical user controls that are directly adjacent to one another. On my screen the form looks fine, but when running a coworkers machine, the window gets resized and the user controls overlap. Does anyone know how i can prevent them from overlapping? I don't mind that the window is resizing on different machines, I just don't want any lost information or partially hidden elements.
Thank you in advance.
You could use a FlowLayoutPanel. It won't work in every situation, depending on what kind of controls you intend to place inside it. I'm not sure what your user control look like, but I just added a FlowLayoutPanel and added about a dozen buttons inside it, and it takes care of
adjusting the layout for me when the end-user resizes the form, maintaining padding around each button and avoiding overlapping.
If your user controls can flow around each other, and it doesn't matter if they are side by side or one over the other, you may want to check this out.

C# custom GUI, better implementation?

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.

Categories

Resources