Friday, January 12, 2007

gradient background control

C#.Every time you need gradient background for a particular control to make your windows application look more visual and appelaing. I have written a code that might help you.
Thorugh this you can created gradient button,toolstrip and menustrip or any control that have background .

Following are code in C#.NET 2.0. Here the example is for menustrip but you can use it for any

class GreenMenuStrip: MenuStrip
protected override void OnPaintBackground(PaintEventArgs e)
Graphics g = e.Graphics;
Rectangle bounds = new Rectangle(Point.Empty, this.Size);

if (bounds.Width > 0 && bounds.Height > 0)

using (Brush b = new LinearGradientBrush(bounds,Color.FromArgb
(183,214,183) , Color.FromArgb(221,235,221),
g.FillRectangle(b, bounds);


  1. Thank you. Simple and elegant. Exactly what I was looking for.

  2. when i minimize and reactivate the control, parts of the gradient background don't show up or are transparent. any way to fix this?

  3. Simple and effective thanks. Just what I was looking for to prettify some tab pages.

    Override 'OnsizeChanged':

    protected override void OnSizeChanged(EventArgs e)

  4. Hi,
    Your article are really awesome.actually i was in search for some good articles on

    Gradient background in c#. and finally i got one.
    The most important is the simplicity which will be very helpful for the beginners. This link ...

    also helped me to complete my task.



Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog


My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews