如何使一个窗口可拖动(C#的WinForms)?拖动、窗口、WinForms

2023-09-06 07:51:37 作者:奋斗的青春才无悔

我有形式。我已经启用表单上的透明度,我已删除了它的标题栏和边框。里面,我已经创建了一个自定义用户界面,其中有这样一个窗口相同的功能。基本上,我的想法是创建自定义窗口。

I have form. I have enabled the transparency on the form and I have removed it's Title Bar and Border. Inside that i have created a Custom UI, Which have the same features like a window. Basically, my idea is to create custom window.

一切工作正常,但只有Windows拖着不工作。我不知道如何启用它。我用Google搜索了这一点。但我没有找到我任何有用的信息。

Everything is working as expected but only the windows dragging is not working. I am not sure how to enable it. I googled for this. But i didn't find any useful info for me.

请帮我实现这个窗口拖动。

Please help me to implement this window dragging.

推荐答案

我实现了通过捕捉鼠标按下(uncapture上的mouseup)这种行为,然后鼠标移动。

I've implemented this behavior by capturing mousedown (uncapture on mouseup), and then mousemove.

刚刚移动窗体坐标(左,上),等量鼠标移动(这些事件让鼠标移动量)。

Just move the form co-ordinates (left, top), equivalent amounts to the mouse movement (those events have the amount the mouse moved).

这工作对我罚款。