In my WinForms app I've long been able to create a linear gradient effect by
just intercepting the PaintEventHandl er event. But I'd now like to create an
inherited user control, specifically of a panel.
I thought I was on the right track and did achieve the effect ... until I
started putting some controls on the panel. Then I got an "Invalid
parameter" error but don't understand what it's referring to.
Based on examples I've found, I've tried two approaches but neither work.
Hopefully someone will know why.
Here are the two approaches:
protected override void OnPaintBackgrou nd(PaintEventAr gs e)
{
Graphics gfx = e.Graphics;
Rectangle rect = new Rectangle (0, 0, this.Width, this.Height);
LinearGradientB rush lgb = new
LinearGradientB rush(this.Clien tRectangle,
gradientColorOn e, gradientColorTw o, lgm);
e.Graphics.Fill Rectangle(lgb, this.ClientRect angle);
lgb.Dispose();
e.Dispose();
gfx.Dispose();
}
protected override void OnPaintBackgrou nd(PaintEventAr gs e)
{
using(LinearGra dientBrush lgb = new
LinearGradientB rush(this.Clien tRectangle,
this.GradientCo lorOne,
this.GradientCo lorTwo,
this.GradientMo de)) //.Rotation))
{e.Graphics.Fil lRectangle(lgb, this.ClientRect angle);
}
base.OnPaint(e) ; //right, want anything handled to be drawn too.
}
Incidentally, dragging a TextBox onto the panel DOES work. But none of the
other basic controls seem to. I don't know if that gives a clue.
--
Robert W.
Vancouver, BC
www.mwtech.com