ComponentOne Themes for WinForms
Themes for WinForms Quick Start / Themes with .NET 5
In This Topic
    Themes with .NET 5
    In This Topic

    This topic showcases the implementation of a simple themes application which includes a C1Ribbon and ComboBox with a list of all the inbuilt themes.

    To create a simple WinForms application in .NET 5 for C1Themes control, complete the following steps:

    1. Initialize the C1Themes object.

      // Initialize C1Theme object
              C1Theme theme;   
    2. Initialize the C1Themes class.

      // Initialize C1Themes class
                  theme = new C1Theme();
    3. Add the following code to the form load event:

      theme = null; 
       // Add C11ThemeController
       string[] themes = C1ThemeController.GetThemes();
       cmb_list.Items.Add("(No Theme)");
       foreach (string theme in themes)
       cmb_list.SelectedIndex = 0;
    4. Add a combobox with name cmb_list and button with name btn_apply.

    5. Add the following code to the SelectedIndexChanged event of the ComboBox.

      private void cmb_list_SelectedIndexChanged(object sender, EventArgs e)
          C1Theme theme = null;
              theme = C1ThemeController.GetThemeByName(cmb_list.Text, false);
          if (theme != null)
              C1ThemeController.ApplyThemeToControlTree(c1Ribbon1, theme);

      The GetThemeByName method in C1ThemeController class retrieves a theme registered with the application, while the ApplyThemeToControlTree method recursively applies a theme to a control.

    6. Run the code and observe the output.


      Also, you can directly apply the specific theme using the following code:

      Copy Code
      var theme = C1ThemeController.GetThemeByName("Office2016Green", false);
      // Apply theme to all controls on the form
      C1ThemeController.ApplyThemeToControlTree(this, theme);

      Note that in the above code, in place of C1Ribbon, you can use a control name specific to your requirement.

      You can also check the product sample specific to the Ribbon implementation with the Themes control, at Documents\ComponentOne Samples\WinForms\C1Themes\C1RibbonBasedApp.

    Note: WinForms .NET 5 Edition does not include rich design-time support yet. We will enhance it in future releases.