gpt4 book ai didi

c# - 仅垂直移动表单

转载 作者:行者123 更新时间:2023-11-30 19:33:05 24 4
gpt4 key购买 nike

如何创建一个仅由 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com