当前位置:网站首页>C#之winform窗体的最大化、最小化、还原、关闭以及窗体的移动
C#之winform窗体的最大化、最小化、还原、关闭以及窗体的移动
2022-07-23 01:10:00 【zcy_wxy】
C#之winform窗体的最大化、最小化、还原、关闭以及窗体的移动
在做winform窗体界面美化时,一般都将窗体的FormBorderStyle属性修改为None,之后窗体将会变成一张空白的“白纸”,然后根据自己的需要进行界面的设计。窗体上的关闭、最小化、最大化按钮都需要自己添加,实现其功能的代码如下:
//窗体的关闭
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
//窗体最小化
private void btnMin_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
//窗体最大化以及还原
private void btnMax_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
Image backImage = Resources.最大化;//这里图片调用的时资源库中添加好的图片 需要添加引用 using CalibrationAndMatching.Properties;
btn_Max.BackgroundImage = backImage;
}
else
{
this.WindowState = FormWindowState.Maximized;
Image backImage = Resources.还原;
btn_Max.BackgroundImage = backImage;
}
}点击窗体最大化按钮后会发现窗体变大后覆盖了整个屏幕,把任务栏都遮住了,解决这个问题的方法如下:
//在窗体的Load事件中编写
private void Form1_Load(object sender, EventArgs e)
{
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
}要想实现窗体的拖动,将如下代码放入到控件的MouseDown事件中即可:
//调用API函数 添加引用using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private void FrmMain_MouseDown(object sender, MouseEventArgs e)
{
if (e.Clicks == 1)
{
//窗体移动
if (e.Button == MouseButtons.Left)
{
ReleaseCapture(); //释放鼠标捕捉
//发送左键点击的消息至该窗体(标题栏)
SendMessage(this.Handle, 0xA1, 0x02, 0);
}
}
}
边栏推荐
- Ascension begins with change
- 涨薪神器
- Online matting and background changing and erasing tools
- Advantages of server hosting, server leasing and virtual machine
- How many of the 50 classic computer network interview questions can you answer? (top)
- 视频点播中相关分辨率说明
- 【高等数学】矩阵的初等变换和行列式的初等变换
- og seo
- Metauniverse is not an existence that regards traffic as the ultimate pursuit like the Internet
- 正则表达式转换为相应的文字小工具
猜你喜欢

Anti attack based on conjugate gradient method
![[cloud native] in the era of storm and cloud, the sharp edge of DBAs is out of the sheath](/img/22/5547663b5c0b4224d9a02d51b0f325.png)
[cloud native] in the era of storm and cloud, the sharp edge of DBAs is out of the sheath

NodeJS 基于 Dapr 构建云原生微服务应用,从 0 到 1 快速上手指南
![[ManageEngine] six essential functions of network configuration management](/img/dc/df353da0e93e4d936c39a39493b508.png)
[ManageEngine] six essential functions of network configuration management

Swin-Transformer-Object-Detection项目安装教程

事件侦听和删除事件——event对象——默认事件——取消冒泡事件——事件委托——默认触发

Software testing interview ideas, skills and methods to share, learn is to earn

万物互联时代,看IoT测试如何应对“芯”挑战

解析创客教育活动所需的空间实践场
How many points can you get on the latest UnionPay written test for test engineers?
随机推荐
Advantages of server hosting, server leasing and virtual machine
NodeJS 基于 Dapr 构建云原生微服务应用,从 0 到 1 快速上手指南
事件侦听和删除事件——event对象——默认事件——取消冒泡事件——事件委托——默认触发
[C language] file operation
transformer汇总
-Bash: wget: command not found
Stream操作之 先分组再取最大值
只有漂亮的才能点开
2022.7.22-----leetcode.757
JMeter --- JMeter installation tutorial
Unity3D学习笔记9——加载纹理
BCG 使用之NOTIFYICONDATA托盘
1646. 获取生成数组中的最大值递归法
求解最大公约数和最小公倍数
Summary of some open source libraries that drive MCU hardware debugger (including stlink debugger)
Online matting and background changing and erasing tools
推荐系统专题 | 推荐系统架构与单域跨域召回模型
Solve the greatest common divisor and the least common multiple
【FPGA教程案例37】通信案例7——基于FPGA的FFT,IFFT傅里叶变换和逆变换
php获取证书编号没有serialNumberHex只有serialNumber处理方法