Hy,
I have a form with transparent BackColor
(MyForm.TransparencyKey=MyForm.BackColor) and the OnPaint method draws
a rectangle with a GradientBrush the gradient is from Color.Black to
Color.Transparent.
The result seems to be a gradient from Color.Black to
SystemColors.Control instead of from Color.Black to whatever is behind
my form.
Why is that?
Any idea how to accomplish the desired effect?
Thanks
///
///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace MyNameSpace
{
public partial class AboutForm : Form
{
private GraphicsPath shadowPath;
private PathGradientBrush shadow;
bool shrink;
public AboutForm()
{
InitializeComponent();
//this.Owner.Deactivate += new
EventHandler(Owner_Deactivate);
Rectangle myRect = new Rectangle(0, 0, this.Width,
this.Height);
this.RightToLeftLayout = false;
this.TransparencyKey = this.BackColor;
shadowPath = new GraphicsPath();
shadowPath.StartFigure();
shadowPath.AddLine(10, 10, 10, myRect.Height);
shadowPath.AddLine(10, myRect.Height, myRect.Width,
myRect.Height);
shadowPath.AddLine(myRect.Width, myRect.Height,
myRect.Width, 10);
shadowPath.CloseFigure();
shadow = new PathGradientBrush(shadowPath);
shadow.CenterColor = Color.Black;
shadow.CenterPoint = new PointF(myRect.Width / 2 + 30,
myRect.Height / 2);
shadow.FocusScales = new PointF(0.9F, 0.9F);
shadow.SurroundColors = new Color[] { Color.Transparent,
Color.Transparent, Color.Transparent, Color.Transparent };
shrink = false;
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle myRect = new Rectangle(0, 0, this.Width,
this.Height);
Rectangle shadowRect = myRect;
Rectangle contentsRect = new Rectangle(0, 0, myRect.Width
- 10, myRect.Height - 10);
e.Graphics.FillPath(shadow,shadowPath);
e.Graphics.FillRectangle(Brushes.SkyBlue, contentsRect);
e.Graphics.DrawIcon (this.FindForm().Icon,new
Rectangle(10,30,60,60));
e.Graphics.DrawString("About Form", this.Font,
Brushes.Black, new PointF(myRect.X + 10, myRect.Y + 10));
}
protected override void OnClick(EventArgs e)
{
this.Close();
}
}
}