Customizing the look and feel of a control is an important part of the application development which is required to give it a seamless user interface. Our Themes for WinForms provides an easy and intuitive way to apply themes to all ComponentOne controls. It allows you to style the control using the ThemeController component and ThemeDesigner application.
The ThemeController component can be used to apply built-in themes to the controls. The component loads and manages visual themes and applies them to the control. You can simply drag and drop the ThemeController from the toolbox on your form and use the built-in themes to style the control. For example, BeigeOne, Material, MaterialDark,Office2016Green, etc. are some available built-in themes.
The following image shows applying themes to the Map control.
To apply a built-in theme to the Map control using designer, follow these steps:
Switch to code editor and add the following code to Form_Load event:
C# |
Copy Code
|
---|---|
string[] themes = C1ThemeController.GetThemes(); foreach (string theme in themes) // Populate ComboBox with themes cmb_themes.Items.Add(theme); cmb_themes.SelectedIndex = 0; |
As you can observe from the code above, the ThemeController component loads and manages C1Visual themes, and the GetThemes method retrieves all themes registered with the application. The Add method adds the themes as items to the ComboBox, and the SelectIndex property selects the current theme in the ComboBox.
Add the following code to the SelectedIndexChanged event of ComboBox:
C# |
Copy Code
|
---|---|
private void cmb_themes_SelectedIndexChanged(object sender, EventArgs e) { C1Theme theme = null; try { theme = C1ThemeController.GetThemeByName(cmb_themes.Text, false); } catch { } if (theme != null) { C1ThemeController.ApplyThemeToControlTree(c1Map1, theme); } this.Activate(); } |
The SelectedIndexChanged event of ComboBox occurs when the value of the SelectedIndex property changes. Further, the ThemeController calls the ApplyThemeToControl method to apply theme to the Map control.
Run the code and observe the output.
C1ThemeDesigner application provides you an easy-to-use UI so that you can create your own themes or modify the existing ones. The application gets installed on your system along with ComponentOne WinForms Edition and can be accessed through C1ThemeDesigner.4.exe located at the following location:
C:\Program Files (x86)\ComponentOne\Apps\vx.x