How to Make gradient colored controls in Windows Forms

Source: Internet
Author: User

This article from http://www.codeproject.com/Tips/104986/How-to-make-gradient-colored-Controls-in-Windows-F.aspx

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:

Collapse | Copy code
 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.