I have a user drawn form with rounded corners. I have set the .TransparencyKey of the form to the background color but when I set the SmoothingMode to .AntiAlias I get a halo effect on the corners when the form is displayed against a light background, as the background color is black. If I change the background color to SystemColors.Control I get the halo when the form is displayed against my dark desktop.
Is there a quick fix to this problem or do I have to (painfully) sample all of the colours used in the anti-alias effect and make them all transparent (if this is indeed possible) to get rid of this halo?
protected override void OnPaint(PaintEventArgs e)
{
Graphics gr = e.Graphics;
LinearGradientBrush GrBrush;
GraphicsPath gPath;
int w;
int h;
w = this.Width;
h = this.Height;
gr.SmoothingMode = SmoothingMode.HighQuality;
GrBrush = new LinearGradientBrush(new Point(0, 0), new Point(0, 75), Color.FromArgb(255, 51, 51, 51), Color.FromArgb(255, 0, 0, 0));
gPath = new GraphicsPath();
gPath.AddArc(new Rectangle(0, 0, 15, 15), 180, 90);
gPath.AddArc(new Rectangle(w-16, 0, 15, 15), 270, 90);
gPath.AddLine(new Point(w-1, 75), new Point(0, 75));
gPath.CloseAllFigures();
gr.FillPath(GrBrush, gPath);
gr.DrawPath(new Pen(GrBrush), gPath);
GrBrush = new LinearGradientBrush(new Point(0, 14), new Point(0, h-1), Color.FromArgb(255, 1, 1, 1), Color.FromArgb(255, 0, 0, 80));
gPath = new GraphicsPath();
gPath.AddArc(new Rectangle(-10, 15, 400, 50), 180, 45);
gPath.AddLine(new Point(w-1, 15), new Point(w-1, 75));
gPath.AddArc(new Rectangle(w-16, h-21, 15, 15), 0, 90);
gPath.AddArc(new Rectangle(0, h-21, 15, 15), 90, 90);
gPath.CloseAllFigures();
gr.FillPath(GrBrush, gPath);
gr.DrawPath(new Pen(GrBrush), gPath);
GrBrush = new LinearGradientBrush(new Point(5, 80), new Point(5, h-6), Color.FromArgb(255, 245, 245, 255), Color.FromArgb(255, 150, 150, 160));
gPath = new GraphicsPath();
gPath.StartFigure();
gPath.AddArc(new Rectangle(5, 80, 10, 10), 180, 90);
gPath.AddArc(new Rectangle(w-16, 80, 10, 10), 270, 90);
gPath.AddArc(new Rectangle(w-16, h-21, 10, 10), 0, 90);
gPath.AddArc(new Rectangle(5, h-21, 10, 10), 90, 90);
gPath.CloseAllFigures();
gr.FillPath(GrBrush, gPath);
gr.DrawPath(new Pen(GrBrush), gPath);
}
Any help would be appreciated. Thx.
|