C# 表单控件移动
是否有办法控制可以移动表单的位置?
因此,如果我移动表单,它只能在垂直轴上移动,当我尝试水平移动它时,什么也不会发生。
我不想要一个有缺陷的实现,比如位置更改或移动事件并将其内联弹出。 我没有办法使用 WndProc 覆盖之类的东西,但搜索了一段时间后,我找不到任何东西。 请帮忙
Is there anyway to control where you can move a form?
So if i move a form, it can only be moved on the vertical axis and when i try to move it horizontally, nothing happens.
I dont want a buggy implementation like locationchanged or move event and poping it back inline. I no there is a way using something like a WndProc override but after searching for a while, i couldnt find anything. Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
例如:
上面的代码将最小左侧位置设置为 100。
无需像 driis 那样重新创建 RECT 结构,.NET 原生 Rectangle 可以正常工作。 但是,您必须通过 X 属性设置位置,因为 Left 是仅获取属性。
For example:
The above code sets a minimum lefthand position of 100.
There is no need to recreate the RECT structure, like driis did, the .NET native Rectangle works fine. However, you have to set the location via the X property, since Left is a Get only property.
您很可能希望重写 WndProc 并处理 WM_MOVING 消息。 根据 MSDN:
这将是一种方法,但是,您显然需要根据您的需要调整它:
You would most likely want to override WndProc and handle the WM_MOVING message. According to MSDN:
This would be a way to do it, however, you would obviously need to tweek it for your needs:
VB.NET版本:
VB.NET Version: