博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[C#][Winfrom]自定义窗体主题
阅读量:6860 次
发布时间:2019-06-26

本文共 1364 字,大约阅读时间需要 4 分钟。

首先在窗体类里面声明两个变量,来监视鼠标的动作

//鼠标按下标识
bool mouseDown = false;
Point mouseOffset;

在Load事件里加载所有的图片

 

if (File.Exists(GlobalInfo.AppPath + "\\Picture\\login.png"))
this.BackgroundImage = new Bitmap(GlobalInfo.AppPath + "\\Picture\\login.png");
 
if (File.Exists(GlobalInfo.AppPath + "\\Picture\\button.png"))
{
this.simpleButton1.ImageLocation = ImageLocation.MiddleCenter;
this.simpleButton1.Image = new Bitmap(GlobalInfo.AppPath + "\\Picture\\button.png");
 
this.simpleButton2.ImageLocation = ImageLocation.MiddleCenter;
this.simpleButton2.Image = new Bitmap(GlobalInfo.AppPath + \\Picture\\button.png);
}

绘制按钮的时候添加上文字

 

//绘制登录按钮
private void simpleButton1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString("登录", new Font("新宋体", 12, FontStyle.Bold), Brushes.White, 30, 8);
}

窗体的鼠标事件

//鼠标按下
private void FrmLogin_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseDown = true;
mouseOffset = new Point(-e.X, -e.Y);
}
}
//鼠标松开
private void FrmLogin_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseDown = false;
}
}
//鼠标按下移动
private void FrmLogin_MouseMove(object sender, MouseEventArgs e)
{
if (mouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
}

转载于:https://www.cnblogs.com/Hsppl/archive/2012/07/20/2601017.html

你可能感兴趣的文章
《当程序员的那些狗日日子》(三十一)特殊任务
查看>>
9.10---堆箱子问题(CC150)
查看>>
Spark技术内幕:究竟什么是RDD
查看>>
新功能!从 Dropbox 部署到 Windows Azure 网站
查看>>
指尖上的电商---(10)SolrAdmin中加入多核
查看>>
CCEditBox/CCEditBoxImplAndroid
查看>>
TCP/IP协议栈--IP首部选项字段的分析
查看>>
Kubuntu 初始配置
查看>>
python中列表和元组的操作(结尾格式化输出小福利)
查看>>
用过的一些服务器集成软件
查看>>
一键拨打
查看>>
20120522:ERROR - ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
查看>>
Maven构建war项目添加版本号
查看>>
更新 手淘 flexible 布局 rem 单位适配问题
查看>>
第三次作业
查看>>
新浪微博登录接口实例
查看>>
wcf技术剖析_会话
查看>>
AngularJS 指令的 Scope (作用域)
查看>>
gitlab的使用
查看>>
iOS 生成本地验证码
查看>>