Click here to Skip to main content
12,831,378 members (29,657 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 26 Aug 2010

How to make gradient colored Controls in Windows Forms

, 26 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Create a class library project, add a customControl item to the solution, then make that class inherits from Panel instead of Control and override the OnPaint method to be like this:

protected override void OnPaint(PaintEventArgs e)
if (this.ClientRectangle.Height == 0 this.ClientRectangle.Width == 0) return; 

//get the graphics object of the control 
Graphics g = e.Graphics; 

//The drawing gradient brush 
LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, BackColor1, BackColor2, FillMode); 

//Fill the client area with the gradient brush using the control's graphics object 
g.FillRectangle(brush, this.ClientRectangle);

build and get the dll, add it to your toolbox and use it instead of the normal Panel, by the way you can do the same thing to all controls to have a better UI


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Asset Technology Group
Egypt Egypt
I'm a professional components designer, web developer, UX engineer and 3d designer as well, I'm 4 years experienced .net software engineer and 7 years experienced 3d designer using 3D Max. I'm very interested in RIA technologies, prototyping and UX engineering.

Ahmed Said
Senior .Net Software Engineer

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170326.1 | Last Updated 26 Aug 2010
Article Copyright 2010 by Ahmed_Said
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid