又经过一个不眠之夜,终于写完了一个支持透明显示的按钮控件和Panel控件。将它们的形状弄得稍微好看一点,而且支持换肤(就是设置皮肤图片了。:-))
附
1、控件透明化设置
要在C#中实现控件的透明化,需要使用SetStyle函数进行设置ControlStyles.SupportsTransparentBackColor为true
2、自绘控件时打开双缓冲
为了实现双缓冲,同样需要SetStyle函数,不过这里不要看你是在.NET 1.1下还是.NET 2.0环境之下使用了,如果是.NET 1.1,设置方法如下:
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
如果是在.NET 2.0下面,设置方法跟其大同小异
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
这里只有最后一次调用SetStyle时用到的参数名不同,效果确实一样的。
以下图片是两个控件的效果图(设计阶段),注意其中按钮上出现了绘图错误,这不是出现在运行阶段的错误,可能是我的编辑器有问题。