关键词: 背景渐变、重写OnPaintBackground方法。

 

 

GradientFill class and the Win32Helper class可以在这找到

 

 

The first thing I started with was to create a gradient background. I found that the best way achieving this would be to override OnPaintBackground in the Screen class. I found a very good article on how to do this on MSDN: How to display a gradient fill . I copied the GradientFill class and the Win32Helper class into my project, I didn’t bother using the GradientFilledButton class since I only needed gradient for my background.

Then I override the OnPaintBackground in my Screen , giving me this Form :

  1. using System .Drawing ;
  2. using System .Windows .Forms ;
  3.  
  4. namespace GradientTransparentTest
  5. {
  6. public partial class GradientTransparentForm : Form
  7. {
  8. public GradientTransparentForm( )
  9. {
  10. InitializeComponent( ) ;
  11. }
  12.  
  13. // Paints the background of the form with a GradientFill pattern.
  14. protected override void OnPaintBackground( PaintEventArgs e)
  15. {
  16. GradientFill.Fill (
  17. e.Graphics , ClientRectangle,
  18. Color.Silver , Color.LightBlue ,
  19. GradientFill.FillDirection .LeftToRight ) ;
  20. e.Graphics .Dispose ( ) ;
  21. }
  22. }
  23. }

This is what my simple Form with Gradient background looks like

参考资料:


http://www.cnblogs.com/chy710/archive/2009/09/15/1567210.html

http://breathingtech.com/2009/creating-gradient-background-with-transparent-labels-in-net-compact-framework/