Crouch
Crouch

Reputation: 896

Remove button border when entered

When I hover over buttons on my C# form I have them highlighted yellow like how Microsoft office products but I don't want it to show the button border. I've seen people mention FlatStyle or FlatAppearance but it doesn't seem to recognize those commands. I'm looking into rendering now but I'm new to C# and I'm certain there must be a simple way to do it, It's not something I want to spend a lot of time on if possible.

I must stress I've been reading through books on windows forms programming and haven't found any answers its not that I'm lazy but I often find SO a very good source with really good input.

Tried this:

this.TSVehicleButton.BorderStyle = None;

Tried this:

this.TSVehicleButton.System.Windows.Forms.BorderStyle = None;

I tried lots of things but didn't mention it as part of my question, I'm new to C# and didn't want to come across as stupid. People get a little bitchy when people put things that they tried and isn't right.

Upvotes: 1

Views: 16184

Answers (5)

Jan
Jan

Reputation: 2273

Just set the following Button properties, for example at design time in the properties window:

FlatStyle=Flat
FlatAppearance.BorderSize=0

Or run the following code, for example for a button named button1:

button1.FlatStyle=True
button1.FlatAppearance.BorderSize=0

Upvotes: 2

Federico Di Cesare
Federico Di Cesare

Reputation: 98

This worked perfectly for me, and it's so simple!

button.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); // transparent
button.FlatAppearance.BorderSize = 0;

Now the button has no borders, even when you enter the cursor. This worked perfectly on Visual Studio 2015.

Upvotes: 1

Fuzz Master
Fuzz Master

Reputation: 11

there is a way of taking the border away from the button and its in the button properties. First make sure you have clicked on the button so that the properties belong to the button. on the properties pane go and find Flat Appearance and expand it by clicking on the + sign in front of it. This will open more option for you, one of the option is border size which is set to 1, change this to 0, Next, 3 lines below that there is a property called FlatStyle and its set to standard, this needs to be changed to Flat. Flat Job done!

Hope this helps

Upvotes: 0

Ahmet Zambak
Ahmet Zambak

Reputation: 131

just use this.FlatStyle = FlatStyle.Flat;

Upvotes: 2

Sharad
Sharad

Reputation: 743

Use following on

public class CustomButton : Button
{
    public CustomButton()
        : base()
    {
        // Prevent the button from drawing its own border
        FlatAppearance.BorderSize = 0;
        FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        // Draw Border using color specified in Flat Appearance
        Pen pen = new Pen(FlatAppearance.BorderColor, 1);
        Rectangle rectangle = new Rectangle(0, 0, Size.Width - 1, Size.Height - 1);
        e.Graphics.DrawRectangle(pen, rectangle);
    }
}

I might help you.

Upvotes: 3

Related Questions