背景渐变

本文介绍如何使用.NET Compact Framework为窗体创建渐变背景。通过重写Screen类的OnPaintBackground方法,并利用GradientFill和Win32Helper类实现自定义背景绘制。

关键词: 背景渐变、重写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. namespace GradientTransparentTest
  4. {
  5. public partial class GradientTransparentForm : Form
  6. {
  7. public GradientTransparentForm ( )
  8. {
  9. InitializeComponent ( ) ;
  10. }
  11. // Paints the background of the form with a GradientFill pattern.
  12. protected override void OnPaintBackground ( PaintEventArgs e )
  13. {
  14. GradientFill. Fill (
  15. e. Graphics , ClientRectangle,
  16. Color. Silver , Color. LightBlue ,
  17. GradientFill. FillDirection . LeftToRight ) ;
  18. e. Graphics . Dispose ( ) ;
  19. }
  20. }
  21. }

This is what my simple Form with Gradient background looks like

gradient background

参考资料:


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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值