如何使窗口可拖动(C# Winforms)?
我有形式。我已启用表单的透明度,并删除了它的标题栏和边框。在其中我创建了一个自定义用户界面,它具有与窗口相同的功能。基本上,我的想法是创建自定义窗口。
一切都按预期工作,但只有窗口拖动不起作用。我不知道如何启用它。我用谷歌搜索了这个。但我没有找到任何对我有用的信息。
请帮我实现这个窗口拖动。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过捕获 mousedown (在 mouseup 上取消捕获)然后 mousemove 来实现此行为。
只需移动表单坐标(左、上),相当于鼠标移动的量(这些事件具有鼠标移动的量)。
这对我来说效果很好。
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).
This worked fine for me.
最简单的方法是处理
WM_NCHITTEST
消息并为自定义窗口的部分返回HTCAPTION
,其工作方式类似于普通窗口中的标题栏。 Windows 将完成剩下的工作。The easiest way is to process
WM_NCHITTEST
message and returnHTCAPTION
for the portions of your custom window which work like the title bar does in a normal window. Windows will do the rest.