Introduction to Material Design in WinForms Apps
Tags: webdev, devops, dotnet, tutorial
Published: 2023-11-06 17:20:00

---
canonical_url: https://developer.mescius.com/blogs/winforms-material-design-introduction
description: Learn about material design in your WinForms applications. See more from ComponentOne today.
---
Material Design is a popular UI style defined by Google and used by many modern applications. With [ComponentOne WinForms Edition](https://developer.mescius.com/componentone/winforms-ui-controls "https://developer.mescius.com/componentone/winforms-ui-controls"), we’ve made Material Design easy to achieve in your classic, .NET Windows Forms applications. In this blog, we will show how to style your entire desktop application with a material-inspired theme.

## Adding Material Themes to WinForms Apps<span class="css-1afrefi" aria-label="Copy"></span>

ComponentOne WinForms Edition includes **Material** and **Material Dark** themes. [ComponentOne Themes for WinForms](https://developer.mescius.com/componentone/winforms-ui-controls/office-design-themes-winforms "https://developer.mescius.com/componentone/winforms-ui-controls/office-design-themes-winforms") makes it easy to theme your WinForms controls with many built-in themes and an easy-to-use Theme designer to create your own themes or modify existing ones.

Below are some examples of what the Material themes look like applied to some ComponentOne WinForms controls:

![winforms_01](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlip8jolyehz7xwu83ua.png)

![winforms_02](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wcml1sclifo76aycl35f.png)

![winforms_03](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u53pw26zb81ynj06ocuw.png)

![winforms_04](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wsog1f57vd59rv20xqc.png)

Material themes can be applied at design time as well as at runtime. You can apply a theme at design time with the Theme Controller dialog or by modifying the App.config file. Let’s look at the different ways to set the theme.

### Setting the Material Theme at Design-Time

The easiest way to set a theme is to use the C1ThemeController component at design-time. It requires that you first download and install ComponentOne WinForms Edition for the version of .NET you are using.

1.  Open a form in your application in the Visual Studio's forms designer.

2.  From the designer's toolbox, locate and drag a **C1ThemeController** and drop it on your form. A dialog box appears, enabling you to select:

    *   Application-wide default theme

    *   Current controller’s default theme

    *   Themes for all supporting controls already on the form.

In the dialog that pops up, the theme is initially specified as "(none)" for all supporting controls already on the form. This prevents unintentional loss of property settings on those controls.

3.  Click the **All to (default)** button in the dialog so that the default theme is set on all controls. _Note: If you've customized some of the controls already, this will be ignored, and the default theme will not be restored_.

4.  Select **Material** from the list of available built-in themes. (or if you already created a custom material theme you can select it here).

5.  Click the **All to (default)** button as mentioned above, to set the default theme on all supporting controls on the form.

6.  Click the **OK** button to close the dialog and apply the specified theme to the controls on the form.

<div class="rich-media-item mediaSingleView-content-wrap image-center css-oqqg55" data-layout="center" data-width-type="percentage" data-node-type="mediaSingle">

<div class="css-nw16oy">

<div data-type="file" data-node-type="media" data-width="800" data-height="600" data-id="bbca7b48-a2ae-4fe5-9b9d-5ec2f74eab17" data-collection="contentId-3415048385" data-file-name="image11.png" data-file-size="21098" data-file-mime-type="image/png" data-alt="WinForms Material Designer" data-context-id="3415048385">

<div id="newFileExperienceWrapper" class="new-file-experience-wrapper css-1lmdzac" data-testid="media-card-view">

<div class="media-file-card-view css-1yn77bd" data-testid="media-file-card-view" data-test-media-name="image11.png" data-test-status="complete" data-test-progress="1" data-version="v2">![WinForms Material Design](//cdn.mescius.io/umb/media/hledjbk5/05-winforms.png?rmode=max&width=641&height=481)</div>

</div>

</div>

</div>

</div>

### Setting the Material Theme using App.config

You can also specify the theme at the application level using the app.config file. Add the C1.Win.C1Themes package to your application, and add the following setting to your App.Config. This will apply the built-in Material theme to your entire application.

```
    <configuration>
      <appSettings>
          <add key="C1ApplicationTheme" value="Material"/>
      </appSettings>
    </configuration>
```

### Setting the Material Theme using Code

The third approach is to set a theme in the code. This is helpful if you need to apply or change the theme at runtime. Here, we use the C1ThemeController static class to apply themes. Just add the C1.Win.C1Themes. package to your application and add the following code to your application before it loads.

```
    C1Theme theme = C1.Win.C1Themes.C1ThemeController.GetThemeByName(“Material”, false);
    C1ThemeController.ApplyThemeToControlTree(control, theme);
```

## How to Customize the WinForms Material Theme

The Material Design color system consists of primary and secondary colors. These colors reflect your application’s branding and styling. By default, we use a green color scheme. We include a sample named MaterialDesign that lets you customize the primary and secondary accent colors for your Material theme. You can save the theme and apply it to your WinForms application later.

To change the color scheme for your theme, follow these easy steps:

1.  Run the Material Theme Designer sample.

    1.  It’s named MaterialDesign installed under \Documents\ComponentOne Samples\WinForms\v4.8\Themes.

    2.  Or download it from [GitHub](https://github.com/GrapeCity/ComponentOne-WinForms-Samples/tree/master/NetFramework/Themes/CS/MaterialDesign).

2.  Click on the “SETTINGS” tab and select template and accent colors based on your brand/theme.

3.  Preview how the theme looks with C1 controls.

4.  Click on the cog icon to open the application menu.

5.  Click on “Save Theme” to save the theme at your preferred location.

6.  Follow the steps from the previous section to apply the theme, but now select your saved theme in step #4.

<div class="rich-media-item mediaSingleView-content-wrap image-center css-oqqg55" data-layout="center" data-width-type="percentage" data-node-type="mediaSingle">

<div class="css-nw16oy">

<div data-type="file" data-node-type="media" data-width="800" data-height="600" data-id="976674e9-97b1-4306-aeef-dda466a72e21" data-collection="contentId-3415048385" data-file-name="material-design-walkthrough.gif" data-file-size="464063" data-file-mime-type="image/gif" data-alt="WinForms Material Design" data-context-id="3415048385">![WinForms Material Design](//cdn.mescius.io/umb/media/y5mlczec/06-material-design-walkthrough.gif?rmode=max&width=644&height=483)</div>

</div>

</div>

## Advanced Customization of the Material Theme

The [ComponentOne Theme Designer Application](https://developer.mescius.com/componentone/docs/win/online-themes/ThemeDesignerAppOverView.html "https://developer.mescius.com/componentone/docs/win/online-themes/ThemeDesignerAppOverView.html") allows easy designing of new themes for any controls in WinForms Edition. It also lets you edit/modify an existing theme to achieve the appearance of your choice, or match with the application theme. You can further use this application to tweak the Material theme to the most granular level allowed by the control.

A theme is an XML file with .c1theme extension that consists of a set of properties and their values (which determines the look and feel of a control). Themes are divided internally into different sections corresponding to different controls. A section, Base Theme Properties, is accessible to all other controls. This section contains a sub-section, Material, which stores the Material properties that can be altered to create different material themes.

For example, let’s start changing our material theme for FlexGrid, where the headers are the primary color.

### How to use the WinForms Material Theme Designer

1.  Open the ComponentOne Theme Designer from the ComponentOne Start Menu. Press Ctrl + N or File > New. Select Material as the base theme for your new theme.

    <div class="rich-media-item mediaSingleView-content-wrap image-center css-17rp0qk" data-layout="center" data-width-type="percentage" data-node-type="mediaSingle">

    <div class="css-9h6i9m">

    <div data-type="file" data-node-type="media" data-width="499" data-height="315" data-id="30ed44d8-6893-4a54-97ad-cdea4fb8ec5a" data-collection="contentId-3415048385" data-file-name="image12.png" data-file-size="10381" data-file-mime-type="image/png" data-alt="Select base theme" data-context-id="3415048385">![WinForms Material Design](//cdn.mescius.io/umb/media/n3ejq3q1/07-winforms.png)</div>

    </div>

    </div>

2.  Click on the BTP Editor button (1). This opens a new Base Theme Property Editor. Select “Material” properties (2). Here, you can see the different colors used in Material:

    <div class="rich-media-item mediaSingleView-content-wrap image-center css-oqqg55" data-layout="center" data-width-type="percentage" data-node-type="mediaSingle">

    <div class="css-1wmzasx">

    <div data-type="file" data-node-type="media" data-width="1280" data-height="984" data-id="14e745fa-9f1a-4c3e-a668-91b20d696011" data-collection="contentId-3415048385" data-file-name="image13.png" data-file-size="183992" data-file-mime-type="image/png" data-alt="Colors used in Material Design" data-context-id="3415048385">![WinForms Material Design](//cdn.mescius.io/umb/media/qcjemfsr/08-winforms.png?rmode=max&width=728&height=560)</div>

    </div>

    </div>

3.  Go to the theme tree and expand the C1FlexGrid node.

4.  Expand C1FlexGrid > Styles > Fixed node. This node would hold the styles for a fixed (header) cell.

5.  Select the ForeColor dropdown to open the color picker.

6.  You can select the Reference tab in the picker dropdown to select the primary color.

7.  You can save this theme and use it as mentioned in the "Applying Material Themes in your application" section. Your FlexGrid should now have a header color based on your primary color settings.

<div class="rich-media-item mediaSingleView-content-wrap image-center css-oqqg55" data-layout="center" data-width-type="percentage" data-node-type="mediaSingle">

<div class="css-9464me">

<div data-type="file" data-node-type="media" data-width="936" data-height="912" data-id="fec92a0d-0a0c-4100-ab18-976b7bb7d710" data-collection="contentId-3415048385" data-file-name="image14.png" data-file-size="118467" data-file-mime-type="image/png" data-alt="Select a primary color" data-context-id="3415048385">![WinForms Material Design](//cdn.mescius.io/umb/media/0enlqrtd/09-winforms.png?rmode=max&width=741&height=722)</div>

</div>

</div>

Share with us how you're designing your desktop applications and how Material theme works with your application.