定义一个资源管理器:
private ResourceManager rm ;
然后使用以下的方法在Form的构造函数中将图片取出来(资源文件名为Skin.resources):
rm = new ResourceManager("SkinWindow.Skin", Assembly.GetExecutingAssembly());
Bottom_Left = (Bitmap)rm.GetObject("Bottom_Left");
…(其它的图片也按照此方法取)
重载Form的OnPaint事件:
Graphics g = e.Graphics;
//手工画窗体的各个部?
DrawMiddle_Left(e.Graphics);//画左边框
DrawBottom_Middle(e.Graphics);//画下边框
DrawMiddle_Right(e.Graphics);//画右边框
DrawBottom_Left(e.Graphics);//画左下角
DrawBottom_Right(e.Graphics);//画右下角
DrawTop_Left(e.Graphics);//画标题栏左边
DrawTop_Right(e.Graphics);//画标题栏右边
DrawTop_Middle(e.Graphics);//画标题栏中间
DrawSys_Button(e.Graphics);//画系统按纽
以下是上述画皮肤方法的具体实现部分,我只举一个画左边框的代码示例,其它的部分请读者举一返三:
private void DrawMiddle_Left(Graphics g) { Brush brush = new TextureBrush(Middle_Left, new Rectangle(0, 0, Middle_Left.Width, Middle_Left.Height)); g.FillRectangle(brush, 0, TITLE_WIDTH, Middle_Left.Width, Height - Bottom_Middle.Height - TITLE_WIDTH); } 衣服穿上了,现在我们的程序就有了不同的外观: public abstract class MouseAction { public abstract void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form); } 然后再来定义出它的各个派生类来表示出具体每个鼠标事件响应的代码。 下面是一个向右拉伸窗口事件的代码响应:public class MouseSizeRight : MouseAction { private int lx; public MouseSizeRight(int LocationX) { lx = LocationX; } public override void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form) { form.Width = ScreenX - lx; form.Invalidate(); } } |
閺€鎯版閹存劕濮�閺屻儳婀呴弨鎯版>>
正在阅读:使用Visual C#制作可伸缩个性化窗体使用Visual C#制作可伸缩个性化窗体
2005-06-15 10:06
出处:
责任编辑:moningfeng
键盘也能翻页,试试“← →”键