简体   繁体   中英

C# Winforms - Flat Button Style - Transparent Border

I've recently created a new control - a flat button - so no border, transparent background, no mouse down color, etc. The problem is, once the app is compiled and running, a black border is around the transparent background. I am going to attach two images - the first is how it looks on the app while running and second is how it looks on the design screen (how i want it to look). I'd appreciate any help getting this border to go away. Thank you!

public FlatButton() : base()
{
    FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    FlatAppearance.BorderSize = 0;
    FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);
    BackColor = Color.FromArgb(0, 255, 255, 255);    
}

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    Pen pen = new Pen(FlatAppearance.BorderColor, 0);
    Rectangle rectangle = new Rectangle(0, 0, Size.Width - 2, Size.Height - 2);
    e.Graphics.DrawRectangle(pen, rectangle);   
}

在应用程式中

在设计师

Try setting TabStop = false; in the constructor of this FlatButton class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM