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

    As mentioned in the QuickStart topic that VS2019 Preview does not have a complete design-time model yet, hence you need to use C1Themes control through the code behind in .NET 5 applications. This topic showcases the implementation of the same by creating a simple 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
       cmb_list.Items.Clear();
       string[] themes = C1ThemeController.GetThemes();
       cmb_list.Items.Add("(No Theme)");
       foreach (string theme in themes)
           cmb_list.Items.Add(theme);
       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;
          try
          {
              theme = C1ThemeController.GetThemeByName(cmb_list.Text, false);
          }
          catch
          {
      
          }
          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:

      C#
      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.