You have to intercept the WM_MOVING notification message that Windows sends. Here's the code:
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);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…