嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
C#界面设计是一件比较麻烦的事情,本例子通过模仿暴风影音的界面,向大家介绍c# GUI皮肤的制作方法
#region 初始化变量
protected int formMinX = 0;//最小化按钮的X坐标
protected int formMaxX = 0;//最大化按钮的X坐标
protected int formCloseX = 0;//关闭按钮的X坐标
protected int formTitleMarginLeft = 0;//标题栏的左边界
protected int formTitleMarginRight = 0;//标题栏的右边界
Image imgTopLeft = (Image)Resources.topleft;//窗体顶部左上角图片
Image imgTopRight = (Image)Resources.topright;//窗体顶部右上角图片
Image imgTopMiddle = (Image)Resources.topstretch;//窗体顶部中间图片
Image imgBottomLeft = (Image)Resources.bottomLeft;//窗体底部左下角图片
Image imgBottonRight = (Image)Resources.bottomRight;//窗体底部右下角图片
Image imgBottonmMiddle = (Image)Resources.bottomstretch;//窗体底部中间图片
Image imgMiddleLeft = (Image)Resources.LeftDrag_Mid;//窗体中部左边框图片
Image imgMiddleRight = (Image)Resources.RightDrag_Mid;//窗体中部右边框图片
Image imgFormMin = (Image)Resources.skin_btn_min;//最小化按钮
Image imgFormMax = (Image)Resources.skin_btn_max;//最大化按钮
Image imgFormClose = (Image)Resources.skin_btn_close;//关闭按钮
Image imgFormRestore = (Image)Resources.skin_btn_restore;//还原按钮
#endregion
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
this.BackColor = Color.Black;
//绘制皮肤
Graphics g = e.Graphics;
//绘制窗体顶部左上角图片
g.DrawImage(imgTopLeft, 0, 0, imgTopLeft.Width, imgTopLeft.Height);
int topRightX = e.ClipRectangle.Width - imgTopRight.Width;
//绘制窗体顶部右上角图片
g.DrawImage(imgTopRight, topRightX, 0, imgTopRight.Width, imgTopRight.Height);
int topMiddleWidth= e.ClipRectangle.Width - (imgTopLeft.Width imgTopRight.Width) 4;
//绘制窗体顶部中间图片(标题栏)
formTitleMarginLeft = imgTopLeft.Width;
formTitleMarginRight = topRightX;
g.DrawImage(imgTopMiddle, imgTopLeft.Width, 0, topMiddleWidth, imgTopMiddle.Height);
//绘制窗体底部左下角图片
g.DrawImage(imgBottomLeft, 0, e.ClipRectangle.Height - imgBottomLeft.Height, imgBottomLeft.Width, imgBottomLeft.Height);
//绘制窗体底部右下角图片
g.DrawImage(imgBottonRight, e.ClipRectangle.Width - imgBottomLeft.Width, e.ClipRectangle.Height - imgBottonRight.Height, imgBottonRight.Width, imgBottonRight.Height);
//绘制窗体底部中间图片
g.DrawImage(imgBottonmMiddle, imgBottomLeft.Width, e.ClipRectangle.Height - imgBottonmMiddle.Height, e.ClipRectangle.Width - (imgBottomLeft.Width imgBottomLeft.Width) 4, imgBottonmMiddle.Height);
//画左右边框
g.DrawImage(imgMiddleLeft, 0, imgTopLeft.Height, imgMiddleLeft.Width, e.ClipRectangle.Height - (imgTopLeft.Height imgBottomLeft.Height));
g.DrawImage(imgMiddleRight, e.ClipRectangle.Width - imgMiddleRight.Width, imgTopRight.Height, imgMiddleRight.Width, e.ClipRectangle.Height - (imgTopLeft.Height imgBottomLeft.Height));
//画右上角按钮(最小化,最大化,关闭)
formMinX = topRightX;
g.DrawImage(imgFormMin, topRightX, 0, imgFormMin.Width, imgFormMin.Height);
if (this.WindowState == FormWindowState.Maximized)
{
imgFormMax = imgFormRestore;
}
else
imgFormMax = (Image)Resources.skin_btn_max;
formMaxX = topRightX imgFormMin.Width;
g.DrawImage(imgFormMax, topRightX imgFormMin.Width, 0, imgFormMax.Width, imgFormMax.Height);
formCloseX = topRightX imgFormMax.Width imgFormMin.Width;
g.DrawImage(imgFormClose, topRightX imgFormMax.Width imgFormMin.Width, 0, imgFormClose.Width, imgFormClose.Height);
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
Invalidate();
}
#region 鼠标拖拽改变无边框窗体大小
const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10;
const int HTRIGHT = 11;
const int HTTOP = 12;
const int HTTOPLEFT = 13;
const int HTTOPRIGHT = 14;
const int HTBOTTOM = 15;
const int HTBOTTOMLEFT = 0x10;
const int HTBOTTOMRIGHT = 17;
protected override void WndProc(ref Message m)
{