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.
Related
I want to use same xaml files for silverlight and wpf version of applications.
Only difference that i need is in styling. I have used styles in xaml. But for silverlight i dont want to use any styling in my xaml files, as styling is defined a application level in the form of themes.
Is there any other way to use same xaml file for silvelight and wpf versions? Otherwise I am forced to maintain separate xaml files.
you can reuse quite a bit of xaml for both, I have projects where I'm linking all the same files, xaml and code behind and it works decently.
A couple of things to be weary of is certain things don't always match up well, for example wpf has a template selector for a itemscontrol and silverlight doesn't.
Using SizeToContent tends to produce different behaviours in the two, I recommend avoiding it, I don't think it buys you anything.
I recommend having a seperate 'base' resource where you can keep your difference in the two files. things like event triggers for example aren't nearly as filled out in silverlight. you would have a base class for each version and they would abstract their differences, you could then mark the keys the same and use them as a static resource in your linked files.
Another big gotcha is you want to watch out for the order events happen for uielements, loaded,layout and apply template events get applied in different orders so if you were to make a templated control you have to be careful there, its not a deal breaker you can work around it, just be aware.
other things to be aware of
-silverlight commands take a little more effort, you have to implement ICommand, this isn't always the case in wpf, I use my implementation to help with sharing the code though.
-wpf is the superset, it has a lot of functions that silverlight doesn't have, Usually they are convienient ways of doing things, you just want to avoid those. Good Examples would be Preview events, not there for silverlight but you can usually find an event to match the behaviour.
Ive been working on a C# project for a while now and I fell it needs change its look.
I have found a UI kit that I really like, which can be seen below:
http://medialoot.com/item/transparent-ui-kit/
Does anyone know how to do this?
Thanks
EDIT: Im using WinForms
EDIT2: Maybe I should convert over to WPF? Is this doable?
You can subclass most common controls and draw their appearance yourself. However, unless for novelty applications I doubt your users will thank you for doing so.
Your example is a library of controls. For you to have an appearance such as that you'll have to create or acquire a similar library of controls and replace all your controls in your project to get that appearance.
If you want to update colors (background, foreground, etc.) and such you can make a class that recurses through controls and sets the settings using reflection and a switch statement to process each control. Then just run this on each form before you show it. One word of caution about this, some controls don't respect your changes and get overridden with themes from the OS (datetimerpicker being the biggest culprit). You'll also need to consider whether your users will appreciate the extra work put in for color/appearance changes.
If you don't have very good design skill and have a good know how about creating such templates, its better to buy them.
And C# is just a language. You're looking to create templates and skins for either for ASP.NET website/application or for windows forms.
Have a look at DevExpress Skins
If you can afford it.
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.
I'm used to the GUI frameworks in Java as well as the QT GUI framework, and I'm used to the various layout managers. It doesn't seem that C# has any layout managers built in, or am I missing something?
2 Year Later Edit
I just want to point out to any readers of this question that in hind-sight, my question was misplaced. With proper anchoring and docking of child controls, having a need for the layout managers of Java and QT4 is nearly non-existent.
WPF does have layout managers, see:
http://msdn.microsoft.com/en-us/library/ms745058.aspx
If you're coming from a Java background, then the section "Panel Elements and Custom Layout Behaviors" will be of particular interest.
Both WPF and Windows Forms provide layout capabilities (WPF is just much better at it).
You can achieve moderately complex layouts in Windows Forms too by utilizing the Dock and Anchor properties of controls. Personally I learned what can be achieved and how through Petzold's book on WinForms. If you don't have access to that book, read this short article.
chibacity is right, WPF is loaded with layout managers, all of them are very good.
However if you're going down the WinForms route, you're stuck with TableLayoutPanel, FlowLayoutPanel and SplitContainer. As well as the usual manual Panel and GroupBox controls.
No, you are not missing anything.
.NET does not have built in layout managers for Winforms/Webforms/Console development.
Probably because Visual Studio has good designers, obviating the need.
WPF and Silverlight (both using XAML) do have them, though they are not exactly the same as the Java ones.
WPF and Silverlight have different "Panels" that work similar to the layout managers in other languages.
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.