TreeView detail architecture question - c#

I've got windows form app I'm developing, and my client wants a TreeView on the left with nodes that when clicked allow their users to work in detail screens on the right. The simplest approach was to create panels which are disabled until the appropriate node is clicked. However, this app is growing and way too much of it is living in the main form.
I'm wondering if it is possible to have one form per node that will open and expand into the detail area on the right, and then close when I am done with it. That way I don't have a single monolithic form, however I am not sure of how to go about that.
Anybody have any insight into how to do something like that?
Thanks.

You should try using UserControls.
Basically, each UserControl is a form (more or less) that you can add to your main form just like you would any other control.

I would inherit from Panel for each page, attach an instance of each Panel-derived object to the Tag property of each TreeView node, and display that (Dock=Fill) when a node is selected.

You can use split controls and load the forms right side but needs to arrange it correctly. As #codethis mentioned, usercontrol is best enough to handle these as their code is written separately. Just you need to pass the parameter (from node selection).
You may need to multiple user controls and place them in your form according to your screen changes.

Related

WPF C# Updating label on second window

Hi guys I have a problem
i need the info I enter in a text box on my main window to update a label on my second window called script.
The text box name is client and the label name is client-label
I have tried many different ways to do this and still not coming right
how can I do this?
PS. I am new to the programming world so please give me step by step instructions anywhere possible :)
Pertinent to your requirement (i.e. two WPF windows with sync controls), it will require quite a bit of coding. Better (simpler) way is to create a pseudo-window, i.e. just a nested layout Grid within you main window containing all controls pertinent to that second window (you can set its visibility to collapse/visible in order to "simulate" pop-up window), and update a second TextBlockon .TextChanged event of the first TextBox (using code behind). Alternatively, you can apply data binding technique is XAML of the same single window.
Note: you can implement a splitter control to resize two 'sub-windows'.
In case you do prefer to implement second window, then refer to this example: Data Binding between two TexBoxes in different windows
Rgds,
The "correct" way for this would probably be to have a view model for each view part in your gui and have them communicate through events.
The Prism framework for WPF will help you with most of the plumbing for this.
Se more about Prism here: http://compositewpf.codeplex.com

Removing control from panel doesn't remove it from the Form?

I have a routine where I loop recursively through all the controls on a form and process some code on some of them.
I add and remove controls through the use of the screen depending on selections the user makes.
I found that panel.Controls.Remove(control1) didn't actually remove it from the form. When I would run the routine that loops recursively through the controls on the form, the control I thought I had remove was still being found.
It didn't "disappear" until I did:
panel.Controls.Remove(control1);
this.Controls.Remove(control1)
Is this expected? Can someone explain this to me, and or point me to somewhere that explains control behavior in Windows Forms.
Thanks!
Clearly the control has the form as its Parent, not the panel. These kind of accidents tend to happen easily with the designer. You can use View + Other Windows + Document Layout to get a good view of the child-parent relationships. You can use drag+drop in this list to fix.

What would be the best course of action for display different form in a single Winform?

Here's a screenshot of my application:
Basically, depending on what option is selected I'd like to show another 'content' which can be a buttons, or forms or whatever.
What would be the best choice for this? Using MDI? I'm really new to this type of thing.
This scenario lends itself well to tab pages, as you'd find on a TabControl.
However, since you already have a mechanism for switching between the content, you might prefer to create a series of Panels whose Dock property is set to DockStyle.Fill. When the user clicks the appropriate heading, you simply need to show the appropriate panel and call BringToFront() on it. This is essentially what the tab control does internally, anyway.
Don't forget to use SuspendLayout() and ResumeLayout() appropriately to reduce flicker, which can be a huge problem in WinForms applications, especially when there are lots of controls.
You can position a TabControl where the buttons are not visible and control it from your buttons.

c# winForms open forms inside mainform

I have programmed c# application i will post screenshot. In this main form is 3 buttons which opens different forms. Now i decided to modify this application I want to Make one main form with strip menu which will open this forms. I used this code but i don't like or i'm doing something wrong. I don't like because there is child controls(minimize, maximize, close) in parent (please see second picture ):
Please advice me something. Is MDI good for such job? Thanks!
Sell sell = new Sell();
sell.MdiParent = this;
sell.Dock = DockStyle.Fill;
sell.Show();`
So my problem is that parent form is not filling when i open child form this is creen how to make that it parent form was filled with child form
Seeing your latest edit, I assume the reason that your child form's content doesn't fill the screen even when it's maximized is because your content/layout is not flexible.
Wherever you've placed the controls during Design Mode is where they're going to end up at run time, regardless of how big or small you make the window. If the window is too small to contain all of them, they'll either be covered up or you will see scrollbars. Alternatively, if the window is made larger than necessary, you'll see a lot of empty space.
The way around this is either to set the Dock and Anchor properties of your controls, which causes them to expand and compress to fit the layout of their containing form. You could also place your controls inside a TableLayoutPanel or FlowLayoutPanel control to help manage their layout.
As far as the question you appeared to be asking originally, I still can't tell if you're opposed to the way an MDI application looks, or if you simply don't understand how to correctly implement it. The clarification comment you offered actually makes things less clear to me—you posted a code snippet, but didn't explain what it means. As I wrote in a comment, there's no (non-hackish) way to show a form that doesn't have minimize, maximize, and close buttons (setting the FormBorderStyle property to "None" does this, but I think this is a silly solution that simply allows you to use the wrong control for the job—it won't behave like a form, the user won't be able to move it around like a form, etc. so why use a form?).
If you truly want to have a single application window with changing content in the center, you should create a series of UserControls. You can lay out each user control with the necessary child controls, just like you would with a form (using the fluid layout techniques I discussed above), add each user control to your main form, set each control's Dock property to "Fill" (so that they fill the entire viewing area), and then write code to simply swap out the currently visible user control in your main form's viewing area. The advantage of using a UserControl versus something like a Panel is that you consolidate all of your code into a single control, much like you would with a Form. You could use a tab control, but if you don't want to show any indication that there are multiple forms (which is what your aim appears to be), this would also be the wrong control for the job.
If you literally want to open child forms inside your main form, as your question title indicates, you should indeed be using MDI. If you don't understand how to do this, you'll need to clarify your question further.
Set MDI Container property to true for your parent form. It will help.
Set
FormBorderStyle = None
for your child forms

How to design the UI for settings according to different options in C# WinForm?

This is a .NET winform application question.
I come to this design from time to time. A simple form. On top of the form you have a list of options to select. According to different option chosen, the body of the form displays a unique panel of setting detail.
How to design this UI in Visual Studio neatly? I have two ideas. First idea is to have many panels, each panel contains setting controls. In runtime, hide all panels but the one according to the selection of option. In this solution, it is hard to organize the controls of the form in VS designer. You need to set the form big to hold all the panels. Panels are put one next to each other. There are many runtime loading code to write. For example, when loading the form, you need to hide panels, reset the form size. When you pick an option, you need to relocate the panels and show/hide them. Tedious!
Second idea is to use TabControl. TabControl is good because the tabs are well organized for you. You don't need to relocate panels and resize the form. All you need to do in runtime is to select the right tab according to options. One thing, you need to hide parts of the TabControl from user because after all it is not a real TabControl. Hiding the tab buttons of the TabControl is not hard but I find that after that there is always a big gap between the tab area and the following part on the form.
Dose anyone have a decent way of designing the UI? Maybe not using panels or TabControls but some smarter way? If TabControl is used most of the time, how to hide and show the tab parts of the TabControl and how to set the margin and border size of the TabControl so no big gap exists? Many thanks to any answer and suggestion.
When I need to do this, I put each group of controls in its own UserControl, and then I can use something else to switch between them. See, for example, Implementing a paged Options dialog on my blog.
I suggest you create UserControls for each of your "setting details" and when the user selects an option you load the accordant UserControl. You might have to adjust the forms size, but therefore you can easily manage all the "setting details" in your IDE.
Using user control is a good way to solve your problem. But you need set them probably in panels and play with properties "Visible" and "Dock".
You don't need to Dock them at "Fill" in design mode. You can set this property à runtime or when needed.
Hope this help.
Sounds like you need some design pattern.
Why not create a UI factory that returns your UI objects as needed/required?

Categories

Resources