When it comes to styling Windows Forms we kept it simple. Studio for WinForms has several built-in visual styles that mimic popular Microsoft application UIs. You can set a visual style by just setting one property on any control. When you set the VisualStyle property on a parent control it will apply to all children that support that style as well. There are several tips and important things to know about visual styles in Studio for WinForms. Continue reading and you’ll be on your way to professional styling in just seconds! Tip #1: Use C1RibbonForm as your MainForm. It supports all of the visual styles and will be a parent to every control in your application. It also provides a completely styled frame that gives your app that professional look-and-feel. To use the C1RibbonForm class follow these steps.
using C1.Win.C1Ribbon;
public partial class MainForm : C1RibbonForm
{
public MainForm()
{
InitializeComponent();
}
}
Now your Form is of type C1RibbonForm and has support for the VisualStyle property. Fill your form with some ComponentOne controls and set the VisualStyle property to see this in action. Tip #2: If you’d like to give your users the option to change the visual style, you can easily persist this information using a user setting. It’s very easy to add a user setting to your project. Open up your application properties page, and on the Settings tab add a property named “VisualStyle.” Then browse to C1.Win.C1Ribbon.VisualStyle for the Type column.
It’s then very simple to access, modify and save the setting in code.
// change visual style at runtime and save
MyProject.Properties.Settings.Default.VisualStyle = C1.Win.C1Ribbon.VisualStyle.Office2007Black;
MyProject.Properties.Settings.Default.Save();
If and how you allow the user to change the style is up to you. Tip #3: Use C1Ribbon and/or C1StatusBar to frame your application. Of course, only use C1Ribbon if it makes sense in your application, but C1StatusBar is a great alternative to the standard StatusStrip.
In addition to providing built-in visual styles, Studio for WinForms also includes several controls that mimic parts of popular Microsoft applications. For instance, C1NavBar is a navigation bar identical to the one used in Microsoft Outlook. C1Ribbon makes it easy to duplicate the Office 2007 and 2010 Ribbon UI in your applications. Tip #4: You can further customize the style of some individual controls depending on what styling capabilities are provided. Below are some notes on creating custom visual styles for certain controls.
By using the built-in visual styles you can turn your battleship grey applications into beautiful, professional looking Office applications in mere seconds!