Sunday, 30 December 2012 16:35

showing gradient colored background in application form

Written by 
Rate this item
(0 votes)

It's nice to show cool gradient color as a
background color of the form in c#.net desktop
application.you can set different colors.

1.first add the frmMain_Paint method in the
Paint event of the form from the form properties
window.

2.then add the method in your form -

private void frmMain_Paint(object sender, 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.White, Color.Green,LinearGradientMode.Horizontal))
{
g.FillRectangle(b, bounds);
}}}

3.run your application,you will see nice gradient
color.change color from White and Green to your
favourite colors and run app again.

Read 1613 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments