c# - 仅垂直移动表单

标签 c# .net winforms

如何创建一个仅由 TitleBar 垂直移动的 WinForms 窗体?

最佳答案

您必须拦截 Windows 发送的 WM_MOVING 通知消息。这是代码:

using System.Runtime.InteropServices;
...
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private struct RECT {
            public int left, top, right, bottom;
        }
        protected override void WndProc(ref Message m) {
            if (m.Msg == 0x216) {  // Trap WM_MOVING
                var rc = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
                int w = rc.right - rc.left;
                rc.left = this.Left;
                rc.right = rc.left + w;
                Marshal.StructureToPtr(rc, m.LParam, false);
            }
            base.WndProc(ref m);
        }
    }

关于c# - 仅垂直移动表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4302440/

相关文章:

c# - 有没有办法根据任意 xml 获取 System.Configuration.Configuration 实例?

c# - 使用 PerformanceCounter 跟踪每个进程的内存和 CPU 使用情况?

c# - 如何显示/隐藏鼠标悬停事件的控件

c# - 为什么当我对行进行更改时 DataRowState 显示已添加而不是已修改?

c# - 继承的 Windows 窗体奇怪行为

c# - ID一次性 : Memory leaks

c# - 如何在 Windows 窗体中创建垂直导航栏?

c# - 使用 LINQ TO SQL 选择单行

.net - 如何在后台运行控制台应用程序(无 UI)?

c# - 标记扩展、构造函数和智能感知