windows-forms-designer - 可拖动的窗体栏
问题描述
我正在制作一个 windows 窗体应用程序只是为了测试我的设计技巧,但我发现轮廓很丑,所以我制作了自己的最小化和关闭按钮,但我不确定如何制作一个可以拖动的面板. 谁能帮我?
顺便说一句,代码是C#。
解决方案
使用事件,我们可以在左键单击 (MouseDown) 和鼠标移动时获取当前位置,我们将当前窗口位置减去我们之前的位置,并添加我们拖动鼠标的距离。
public partial class Form1 : Form
{
private Point windowLocation;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
this.windowLocation = e.Location;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Refers to the Form location (or whatever you trigger the event on)
this.Location = new Point(
(this.Location.X - windowLocation.X) + e.X,
(this.Location.Y - windowLocation.Y) + e.Y
);
this.Update();
}
}
}
推荐阅读
- c# - 如何使用 ASP.NET Core 更改数据库的输出文件夹?
- javascript - how to get paragraph element displayed on hovered over input element
- node.js - 我需要 Nginx 用于生产,我可以只使用 Nodejs 服务器吗?
- java - 扩展应该不那么通用的泛型类
- cakephp-3.0 - CakePHP 一些表单在提交时立即重定向而没有表单数据
- shell - 通过使用命令行参数调用 curl 在请求正文中发送数据
- angular - 表单控件的角度设置值给出错误
- .net - Azure Application Insights 是否提供任何内置方法来匿名化用户数据?
- javascript - 如何在Javascript中找到数组中最后一个重复元素的索引?
- java - Html2Pdf 转换器禁用文本选择