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.

Search This Blog
About Me
My Photo

Full Stack Developer,Blogger,Microsoft Mvp, Mentor, Life long learner, 10+ Years of Experience for JavaScript, web and Microsoft technologies. ASP.NET MVC,Web Forms,C#,AngularJs,Golang
Mvp profile
Subscribe to my blog

Enter your email address:

Follow us on facebook
Blog Archive
Total Pageviews