can you have too many user controls - c#

I am putting together a winforms project and I was thinking of using user controls with one form. For example, having a user control for customer lists, customer detail, product list, product detail, etc.
If this is a good idea, if the user is moving from one screen to another do you just make the user control visible = false or do you null it out?

It seems like you are grouping like functionality so I do not think you have to many. Some of the projects that I have done have had pages with a large amount of resources I converted those to usercontrols and I create each time I show them, otherwise if they are relativly lightweight changing their visibility will work fine. It all boils down to what you are trying to accomplish.

Related

Is there a way to duplicate and access designer drawn controls in Winforms?

I want to create a set of controls in the designer and then replicate it over and over again. Here's a picture to help visualize what I'm describing:
Currently I program the position of each control to fit properly in the panel. Doing it this way is tedious and I have to run the program each time I make a change to make sure everything lines up the way I like it. This is the fourth iteration of this panel and I'm getting ready to do at least two more designs for different customers who want slightly different ways of displaying the same data.
Is there a way to draw the panel and its controls in the designer, the programmatically replicate the entire set of controls, and bind different data to each of them?
If you want to allow customer to move these controls around, you need:
Create persistence storage. Basically, your control needs to build itself from some sort of file or better - database, where all the positions and other properties will be set, saved, etc.
Develop a "design mode" for customer. Customer will click button "Design" and be able to move controls around, re-size them, etc. For you, in design mode you want to make controls druggable and also, you need to devise a way for resizing them too. Then customer clicks "Save" and control data should save into the persistence storage.
Now, if you ok with reimplementing multipple looks for customers and want to do it quickly - create a UserControl, place TableLayoutPanel on it and then use series of TableLayoutPanel's to give any look to your control. This is rather fast way. And if I only needed to do it 10 times, I would just create a control factory, and add every new implementation into it. Let customer pick out of existing implementations. Because creating designer will be rather involved effort.

WinForms UI design advice for list of custom controls?

We need a "dashboard" view for a trading application on a C# .Net WinForms application.
Currently the application pops up additional forms with price charts for each symbol (MSFT, GOOG, EUR/USD) for which the user has defined automated trading rules. But some users want to trade dozens or hundreds of symbols simultaneously. The application handles this performance-wise but this creates far too many separate charts on the desktop.
So the need is for a form with a list of information and controls for each of the symbols.
Please offer advice on selecting which controls to use for this.
Okay so here's some requirements:
The list needs to be scrollable.
On Each Row:
a) a button to maximize/minimize the chart for that symbol.
b) a button to pause or resume trading on a symbol as well as show current status.
c) A few columns of information like symbol, equity, position.
Future version: Rows sortable by the information columns.
Future version: Make each row "explandable" maybe with a plus/minus sign to
show additional detail like list of active orders or perhaps a mini "inline" chart
rather than separate popup.
One or more rows will be "portfolio" rows with similar columns to display combined
equity for its nested symbols and portfolios.
We need to implement this as quickly as possible so this rules out designing custom
controls (at least in this version)--So we want to use only the .Net standard controls.
We want to avoid 3rd party solutions unless it's open source.
Trickiest design question:
How to represent the relationships between the strategies and portfolios.
These relationships can be sophisticated with nested portfolios and a single portfolios
instance can be assigned to multiple parent portfolios. Note. The user can't
alter these relationship at run time...but it will be nice to represent this
visually. Can that be integrated into this control--like a tree view? The problem
is that a single portfolio or symbol can be nested inside multiple other portfolios.
So that doesn't seem to make sense for a tree view.
Another idea will be to pop up separate list views for each portfolio--yuck.
The best will be some clever idea to represent the relationships visually on the
same dashboard. Maybe not in this first version but perhaps a custom drawing
control that actually shows a column per portfolio with a vertical line showing
symbols or portfolio contained with tick marks? We'd like a simple yet
elegant solution.
The plan is to get something up and working with the minimum needs but also some forethought into how to get the portfolio relationship and other features in a next version w/o rewriting the whole thing.
if you know winform better then I think you can try to use some tab control ,nested tab control,resizable panel,etc for your dashboard with backgrounds workers thread control .

Winforms GUI controls distribution

I have a winforms tab control which has several tab pages. Within each tab page controls (textboxes, radio buttons, etc...) are group into groupboxes. These group boxes are arranged from top to bottom but in some occassions some groupboxes needs to be visible and other ones to be hidden. Also control within each group box sometimes (depending on the scenario) needs to be visible and sometimes hidden. So I would like to know if someone knows a good approach to do this, maybe some kind of pattern if any. Also it would be good to implement a generic solution to do this. Could any expert in GUI guide me in the right direction to do this?
Using C# and dot NET Framework 4.0, WinForms. This is a desktop application, not Web-based.
You can define the scenarios in a class then add another class that will manage the layout by reading the scenario and laying the elements based on the scenario. I have not provided details because it varies on how specific you want to be and what behavior you want to achieve. It is better to put the Widgets inside a User Control and let that user control communicate with the layout manager.You can use the Mediator pattern or variation of it to coordinate between the widgets. Hope this helps.
I usually try to group related controls into UserControls (even if this means doubling up on some controls) and adding them to or removing them from the form as needed. An example of this could be payment methods - when the user selects a specific payment method (Credit Card, Cash, Cheque, etc) a UserControl with the correct elements is displayed within a panel on the form.
A good pattern to use when managing this sort of set up is Model-View-Presenter, in the example, all the UserControls would probably implement an IPaymentMethod view interface and provide a way to update the corresponding models.

usercontrol vs iframe, limitations and known problems

If this is too hypothetical and needs to be somewhere else, please let me know.
I have a project that needs specific gridviews to appear on multiple pages. Instead of copying and pasting the gridviews on each of the pages I thought creating a user control for each specific gridview or create a page for each gridview and then use iframes would be my best options.
I have not used either extensively so I am looking to the SO community's experience, are there known problems with using user controls and/or iframes when it comes to:
validation
communication between user control/iframe and parent page
ajax/updatepanels containing user control/iframe
thanks in advance
Since a gridview is essentially a user control (that's very flexible), I would first explore doing this with neither of your options. If possible, use the standard gridview and let your data layer do most the work. However, assuming you already know that... but your requirements require one or the other of your options, here are things to consider.
An iframe is easy to implement but unless your need is really simplistic in terms of user interaction, the user control will be the most flexible. Another downside to an iframe is it's size (you're essentially loading two pages). The downside of user controls are the upfront time in building them.
Based on your criterion:
1. validation - can do with either option but you'll have more flexibility with a user control
2. communication between user control/iframe and parent page - much easier with user control unless query string parms will do the trick
3. ajax/updatepanels containing user control/iframe - again user control

How to change into different sections of your application easily

Im currently trying to create an application that will require 10+ different "pages" with different content and controls, and i need to switch back and forth between them on particular events.
What ive been doing, is just creating all the different sections in grids, and setting their visibility to collapsed, and then when i need to show them, just switch out the visible grid to the new one.
This has several drawbacks, im assuming its very poor from a coding standpoint, and this pretty much dis-allows me from using the designer at all. (i have no idea what performance implications it has, either)
on top of that, every time i switch to the new page, i need to reset all the components (textbox's etc) to their default states, as they dont get reset by becoming invisible :P
on to my question: i need a way to map out all the different pages, provide visually attractive transitions between them, and be able to use a designer to create them (and i dont mean designing it somewhere and then just copying the xaml)
I had looked around, and ran into SketchFlow and it seemed like the perfect solution, i could fade between pages and map everything on a flow chart easily, and then i realized it was only for app prototypes and i couldnt actually compile it as a normal application... and i needed to inherit from a custom Window class aswell.
is there something out there that allows me to do this? or how can i code this to work properly?
note: this ABSOLUTELY needs to stay within one window. i cant venture out into having 10+ different windows that pop up every time i need to change to something. as this happens very frequently
Split the separate sections in individual user controls. This would allow you to design each of them easily. Then on your form use code to create and load a new instance of particular user control that represents the section you need to show, and when transitioning, load the new section and unload the current. this would allow your form to stay relatively lightweight.
An alternative is to create a navigation application and split your sections into separate XAML view and use the standard navigation service to switch between them.
WPF Navigation Overview
Creating Navigation Applications video tutorial
You might wanna convert your "Pages" to usercontrols and use some transitions like mentioned in the below link to switch between controls
http://www.tanguay.info/web/index.php?pg=codeExamples&id=280
for more on using transitions look here
http://www.japf.fr/2009/04/adding-transitions-to-a-mvvm-based-dialog/
or
http://www.japf.fr/2008/07/8/comment-page-1/

Categories