How would I make the background of a form (which is usually one boring color) a dynamic gradient, measuring by size of the form and creating the gradient from there?

Thanks

create a lineargradientbrush and on the forms paint event fill the clientrectangle spluah!

protected override void  OnPaint(PaintEventArgs e)
        {
 	      base.OnPaint(e);

          using (LinearGradientBrush lgb = new LinearGradientBrush(this.ClientRectangle, Color.Blue, Color.Black, 90f))
          {

              e.Graphics.FillRectangle(lgb, this.ClientRectangle);

          }
        }

don't forget to add the namespaces:

using System.Drawing.Drawing2D;
using System.Drawing;

have fun!

I believe we have a new resident Daniweb C# Drawing master :)

Danny: Anything math/science related
Serkan: Deployment Projects (if he answers!)
Diamonddrake: Drawing & Controls
Adatapost, Ramy and myself: More random Q&A than anything.

I'll create a roster in the .NET Developers groups after I submit the idea to the community feedback center and watch it probably get rejected.

Edited 7 Years Ago by sknake: n/a

Comments
Well said. It's a good idea.
Sounds like a good idea :)

I believe we have a new resident Daniweb C# Drawing master :)

Danny: Anything math/science related
Serkan: Deployment Projects (if he answers!)
Diamonddrake: Drawing & Controls
Adatapost, Ramy and myself: More random Q&A than anything.

I'll create a roster in the .NET Developers groups after I submit the idea to the community feedback center and watch it probably get rejected.

Don't forget me! -: the unrelenting random Q's. :P

This article has been dead for over six months. Start a new discussion instead.