How to make gradient colored Controls in Windows Forms
2010-10-28 10:32
435 查看
本文转自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
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
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
相关文章推荐
- How to: Host Controls in Windows Forms DataGridView Cells (CalendarCell)
- How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application
- How to: Make Thread-Safe Calls to Windows Forms Controls
- How to: Make Thread-Safe Calls to Windows Forms Controls
- How to: Make Thread-Safe Calls to Windows Forms Controls
- How to: Make Thread-Safe Calls to Windows Forms Controls
- How to make windows access web server in VM linux OS
- How to make Windows Form app truly Full Screen (and to hide Taskbar) in C#? 转
- 【摘自Devx】How to pass parameters to Thread in Windows Forms -- and get results back
- XAF How to show custom forms and controls in XAF (Example)
- How to make a call in Windows Phone 7 application
- How to Make Custom Drawn Gradient Backgrounds in a Grouped UITableView with Core Graphics
- How to Make Custom Drawn Gradient Backgrounds in a Grouped UITableView with Core Graphics
- How to brute force http forms in windows
- How to Make Windows Start Up Faster---如何提高windows启动速度
- How to enable Hibernate option in windows 2008 R2 server?
- How to Use OLE in Rich Edit Controls
- How To Make a Custom UIView in iOS 5: A 5 Star Rating View[转]
- How to make JDev run ant script in debug mode permanently
- How to get the handle in windows using python