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
control.


class GreenMenuStrip: MenuStrip
{
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(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),
inearGradientMode.BackwardDiagonal))
{
g.FillRectangle(b, bounds);
}
}
}
}
Share:

4 comments:

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

    ReplyDelete
  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?

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

    Tim,
    Override 'OnsizeChanged':

    protected override void OnSizeChanged(EventArgs e)
    {
    this.Refresh();
    }

    ReplyDelete
  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 ...
    http://www.mindstick.com/Blog/161/Gradient%20background%20in%20c

    also helped me to complete my task.

    Thanks

    ReplyDelete

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 You tube channel- Please Subscribe
Youtube Video Playlist
My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews