关键词: 背景渐变、重写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 :
-
using System . Drawing ;
-
using System . Windows . Forms ;
-
-
namespace GradientTransparentTest
-
{
-
public partial class GradientTransparentForm : Form
-
{
-
public GradientTransparentForm ( )
-
{
-
InitializeComponent ( ) ;
-
}
-
-
// Paints the background of the form with a GradientFill pattern.
-
protected override void OnPaintBackground ( PaintEventArgs e )
-
{
-
GradientFill. Fill (
-
e. Graphics , ClientRectangle,
-
Color. Silver , Color. LightBlue ,
-
GradientFill. FillDirection . LeftToRight ) ;
-
e. Graphics . Dispose ( ) ;
-
}
-
}
-
}
This is what my simple Form with Gradient background looks like
参考资料:
http://www.cnblogs.com/chy710/archive/2009/09/15/1567210.html