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);
}
}
}
}
Friday, January 12, 2007
Thank you. Simple and elegant. Exactly what I was looking for.
ReplyDeletewhen i minimize and reactivate the control, parts of the gradient background don't show up or are transparent. any way to fix this?
ReplyDeleteSimple and effective thanks. Just what I was looking for to prettify some tab pages.
ReplyDeleteTim,
Override 'OnsizeChanged':
protected override void OnSizeChanged(EventArgs e)
{
this.Refresh();
}
Hi,
ReplyDeleteYour 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