0

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);   
}

In App

In designer

rashfmnb
  • 9,959
  • 4
  • 33
  • 44
siegs
  • 597
  • 1
  • 4
  • 14
  • You could try setting NotifyDefault to false, as per [this question](http://stackoverflow.com/questions/9966462/remove-button-border-on-tab-c-sharp-winforms)? – ManoDestra Apr 21 '16 at 15:04
  • 2
    Can't answer your question, but remember to `Dispose()` your `Pen`! – adv12 Apr 21 '16 at 15:07
  • NotifyDefault did not work – siegs Apr 21 '16 at 15:12
  • `Borders` can't have a `Color.Transparent`. Cheating with `Color.FromArgb(0, 255, 255, 255)` gets around the compiler/designer error message but still doesn't work. Maybe setting `BorderSize=0` will help? – TaW Apr 21 '16 at 15:30
  • 1
    It's enough to set `FlatStyle = System.Windows.Forms.FlatStyle.Flat;` then `FlatAppearance.BorderSize = 0;`. Why do you want to override `OnPaint`? – Reza Aghaei Apr 21 '16 at 17:06
  • Also: Drawing with a Transparent Color as you do will __not draw anything__ unless you also set `e.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;`.. – TaW Apr 21 '16 at 17:16

1 Answers1

0

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

Avinda
  • 86
  • 8