Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you make a new FlatButtonAppearance object?

I’m running into a frustratingly stupid problem with the FlatButtonAppearance object, which apparently has a constructor that I can’t find any information about.

It doesn’t seem to have any defined constructors, and doesn’t inherit from anything – I was under the impression that the compiler would generate a blank constructor public FlatButtonAppearance() {}, however that doesn’t appear to be the case.

Whenever I try creating a FlatButtonAppearance object using any of the following methods:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

FlatButtonAppearance flatAppearance = new();
FlatButtonAppearance flatAppearance = new()
{
    BorderSize = 1,
    BorderColor = Color.Transparent,
    CheckedBackColor = Color.Transparent,
    MouseDownBackColor = Color.Transparent,
    MouseOverBackColor = Color.Transparent
};

It throws this error:

error CS1729: 'FlatButtonAppearance' does not contain a constructor that takes 0 arguments

So clearly it does have a constructor, however neither intellisense nor MSDN will tell me what its signature is.
Even Visual Studio’s metadata doesn’t show a constructor.

The only way that I can find that actually works is this:

FlatAppearance flatAppearance = new Button().FlatAppearance;

but Button has to get that from somewhere too, and creating an entire button control just so I can use the FlatAppearance property is just a dirty hack.

Is there something I’m missing here?

>Solution :

Based on your response comment, you could do something like this:

public abstract class TabHeaderButtonBase : ButtonBase
{
    public TabHeaderButtonBase() : base()
    {
        FlatAppearance.BorderSize = 1;
        FlatAppearance.BorderColor = Color.Transparent;
        FlatAppearance.CheckedBackColor = Color.Transparent;
        FlatAppearance.MouseDownBackColor = Color.Transparent;
        FlatAppearance.MouseOverBackColor = Color.Transparent;

        /* You'll probably want this as well... */
        FlatStyle = FlatStyle.Flat;
    }
}

Then use this type as the base for your custom buttons.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading