Docking Tab for WinForms | ComponentOne
In This Topic
    Themes
    In This Topic

    A user can apply themes to the DockingTab control in the WinForms application by selecting one of the built-in themes, which can be accessed by adding the reference assembly C1.Win.Themes assembly. Latter provides the ThemeController component, for the user to populate themes in the DockingTab control.

    GIF showing changing themes in DockingTab

    Follow the steps below to add the Themes functionality to DockingTab through code.

    1. Drag and drop a ComboBox on the form.

    2. Drag and drop the ThemeController and DockingTab controls on the form. Observe how the ThemeController component gets added to the component tray.

    3. 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.

    4. 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(dockingTab, 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 DockingTab control.

    5. Run the code and observe the output.