Dealing with control flexibility - c#

I've a question more about 'Good Programming Practices'.
I have just started a really big project. I'm using WebGui (long story short.. it is WinForms in web) - but it's not important.
I'm creating milions of forms with milions of controls like TextBox, NumericUpDown, DateTimePicker and etc. It might happen, that I will have to change something in behavior of DateTimePicker or appearance. It will be impossible to change it in every control. I want my project to be flexible so I've got an idea..
I do separate custom controls for every type - string, numeric, date, byte.. and within I will put TextBox for example. And on every form I will put not TextBox, but MyTextBox. In fact, that MyTextBox will be just TextBox, but when I change something there, every control will be changed.
Is it good, popular pracitce in programming?

in the case of WPF this can be achieved quite easily using Styles and Templates.
in Winforms this is not possible, therefore I'd say your approach of deriving from the controls and using your own custom controls on the UI is a good practical approach which helps managing changes centrally.
If the controls were created manually in the programme, alternatively you could use a Factory clase(s) and get the Factories to create the controller object rather than just newing up.
But this might not be possible when the UI is created by dragging and dropping controls as the developer has no control over the creation of controls.
Which ever the approach you choose, the fundamental goal should be to centralize the creation logic of the controlls.

Yes, this is perfectly normal programming practice for GUI development, if the standard controls don't satisfy your requirements.
Most developers get 3rd party control suites for the extra flexibility. The benefits in buying far out weigh the benefits in building core controls yourself.
I've worked at a place that did companyTextBox, companyDatePicker and it worked ok. A couple of controls got revamped over .Net versions so these base classed controls required some surgery. Any depreciated controls were left as framework version dependent.
For special things, I do a lot of research into good custom controls on CodeProject, CodePlex, Code.Google.com,etc and implement them into the project I'm working on.
Otherwise use the stock standard controls or the suite of 3rd party controls the company I'm working for use.
My advice is to get a 3rd party suite of controls and make a ton of re-usable user controls based on the 3rd party ones. This way you can build most of the 200 forms by Drag and Dropping the user controls onto the forms. Make each User-Control Implement an Interface with Create,Retrieve,Update & Delete methods for the forms to generically work with your user controls.

Related

C# Multi-panel/layer winform application

I've been designing a pretty complicated avionics application. The thing is, it has many menu buttons to be clicked (12 to be exact) and each one of them perform a different action. For instance, one could be a login panel and the other one a PDF reader. How could I organize this programmatically?
Currently, I've been setting each item in a panel and setting it to visible or invisible, according to the active or clicked item.
How would you guys do this?
Thanks in advance!
You might consider a FlowLayoutPanel, although I'm not sure how flexible it would be in meeting your requirements. If you set your panels up with docking properties, you should be able to manage.
I would also recommend using a UserControl to separate code and functionality. If panels need to communicate, implement the observer/observable pattern instead of subscribing to events between user controls.
Like IAbstract says, you should consider separating the different UI elements as UserControls. You can then do things like use a factory to construct them and add them to your window as required.
I've found this sort of approach, used with a Model-View-Presenter type pattern, works really well for WinForms apps with dynamic user interfaces.

Stylesheets for .NET Windows Controls

I was wondering is there any option of using Stylesheets for .NET Windows controls ?
If not, which is the best way to make the UI look consistent.I need to use VS 2005 to make
the changes in the UI.
Regards
We derive usercontrols from all controls in our system -- all the derived classes do is set the style from a central list of constants defining colours and fonts. Then we use these controls on our WinForms for a consistent look and feel.
If we want to change the style, we just change the list of constants.
This also allows is to perform UI tricks like setting the background colour of controls to a different colour when they are being edited.
If you want to make your UI consistent and pretty, why don't you give WPF a try? You will be able to organize your styles in resource dictionary, then reference to it in all the other projects.
Well guess he's talking about WinForms. Then you cant use Stylesheets. Havnt coded that much of WinForms. But guess you could have an "Settings/sheet" class that have properties of different style you are using and then set them when creating your controls.
you can use Stylesheets in web pages only not in Windows controls.
Even ASP.NET controls, which ultimately render HTML, are notoriously CSS-unfriendly. The reason is that they use tables extensively for layout, and they set a lot of inline style tags which of course do not honor the style sheet. Some work has been done to create wrappers for these controls, but it was incomplete the last I looked.
It's a shame, but our team will not use the out-of-the box controls most of the time. We've rolled our own and packaged them into an internal library. While the Microsoft controls would have been very useful, they simply don't meet our criteria for clean, accessible, styleable HTML.
Microsoft seems, finally, after something like 10 years, to have realized that this is important to a modern development team. The control output of ASP.NET MVC is far cleaner and behaves itself quite well with respect to CSS. Whether they'll eventually revisit the core ASP.NET controls is anyone's guess.

Rounding the tab headers in Windows Forms

I created a TabControl using Windows Forms but the tab headers look very ugly. I want to make them with rounded corners and also create some space between two tab headers. Can anyone please tell how it can be done using C#.
Thanks,
gary
You'll want to do one of a few things:
Make your own custom control that inherits from TabControl and overrides its render method.
Download a third-party custom tab control that does what you want.
Switch to WPF, which gives you some more flexibility in the way of creating and styling controls.
There isn't a way to do this with System.Windows.Forms.TabControl out of the box, so you'll have to either live with what you've got, or roll your own.
Not to spark any heated debate, but WinForms is an aging API. If you're building a brand new application and/or learning a UI framework for the first time, you might consider using WPF instead. For legacy code, it's fine to maintain WinForms of course.
The System.Windows.Forms.TabControl class is just a wrapper around the Windows COMCTL32 tab control. Unfortunately, that control doesn't provide much in the way of customization options. You'll have to switch controls, either to WPF, custom code, or some third-party product.

Creating a custom menu in .NET WinForms

Using .NET 2.0 with WinForms, I'd like to create a custom, multi-columned menu (similiar to the word 2007 look&feel, but without the ribbon).
My approach was creating a control, and using a left/right docked toolstrip, I have constructed a similar look&feel of a menu. However, there are a few shortcomings of this solution, such as
the control can only be placed, and displayed within the form;
if the form is too small, some area of the control won't be displayed;
the control also have to be manually shown/hidden.
Thus, I'm looking for a way to display this control outside of the boundaries of the application. Creating a new form would result in title-bar deactivating on display, so that's also out. Alternatively, any other approach to create a customized menu would be very welcomed.
Edit: I don't want to use any commercial products for this; and since it's about a simple menu customization, it's not related to Microsoft's ribbon "research" in any way.
unless you are in the business of providing .net components, you should be looking to buy it off the shelf. Its a lot of work getting such a control right - There are already vendors providing this kind of UI. e.g. ComponentOne
if you are trying to build this component as a product, you should look at the link below. Apparently Microsoft has a 'royalty-free' license around the Office UI to protect their R&D investments. As of now you need to tell them that you are using something similar to the Office UI. More of that here
The MenuStrip class has a Renderer property. You can assign your own ToolStripRenderer derived class to customize the painting. It's a fair amount of work.

What is the best way to create a wizard in C# 2.0?

I have a winforms application where users will be creating stock items, and a time of creation there are a number of different things that need to happen.
I think the UI for this should probably be a wizard of some kind, but I'm unsure as to the best way to achieve this. I have seen a couple of 3rd party Wizard controls, and I have also seen manual implementations of making panel visible/invisible.
What are the best ways that people have used in the past, that are easy to implement, and also make it easy to add "pages" to the wizard later on if needed?
I know this answer has already been accepted, but I just found a better Wizard control that's free, and of course, since it's on CodeProject, includes the source, so you can modify it if it's not exactly what you want. I'm adding this as an answer for the next person to stumble across this question looking for a good Wizard control.
http://www.codeproject.com/KB/miscctrl/DesignTimeWizard.aspx
Here are a few more resources you should check out:
This DevExpress WinForms control: http://www.devexpress.com/Products/NET/Controls/WinForms/Wizard/
A home-grown wizards framework: http://weblogs.asp.net/justin_rogers/articles/60155.aspx
A wizard framework by Shawn Wildermut part of the Chris Sells's Genghis framework: http://www.sellsbrothers.com/tools/genghis/
Use a tab-control inside a form.
Change back color to "Control" in all tab-pages.
Set "appearance" to flat buttons to get rid of the white border-stuff.
Hide the tabs by sizing the entire control so that the tabs gets pushed up "under" the title bar of the form. If you need other controls (or banner maybe) above the tab-control, then instead hide the tabs with a panel-control or similar.
Childplay to code logic for back/next buttons and very easy to extend with new pages.
Take a look at this article on MSDN about "inductive user interfaces". It describes a framework (and provides the code to download) based on UserControls that give you "navigation" within a form. Perfect for designing wizards.
The easiest way to create a wizard dialog is to use one of the third-party versions available that handle all of the "hard stuff" (the page navigation, UI framework, etc.) for you. The one I like the most is from Divelements; they have both a WinForms and a WPF version.

Categories

Resources