Search code examples
c#.netwinformsmmc

Form has different style when shown from MMC snap-in


I'm displaying a dialog in an MMC snap-in. When the dialog is called from the result pane it has the Windows theme.

Screenshot of buttons when called from the result pane

However when the dialog is called from the snap-in scope pane context menu it has a different style.

Screenshot of buttons when called from context menu

The snap-in is written in C++ and the dialog is a C# form. The C++ code calls the C# code via COM.


Solution

  • Calling Application.EnableVisualStyles() enables visual styles for your application. In an application the method is called usually in Main method of your application. But in this case, you can call Application.EnableVisualStyles() in constructor of form:

    public Form1()
    {
        InitializeComponent();
        Application.EnableVisualStyles();
    }
    

    Application.EnableVisualStyles Method

    This method enables visual styles for the application. Visual styles are the colors, fonts, and other visual elements that form an operating system theme. Controls will draw with visual styles if the control and the operating system support it. To have an effect, EnableVisualStyles() must be called before creating any controls in the application; typically, EnableVisualStyles() is the first line in the Main function.