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

Recommended Answers

All 3 Replies

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.

commented: Sounds like a good idea :) +4
commented: Well said. It's a good idea. +17

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.