我有一个无边界的可移动表单(通过单击并按住鼠标按钮在周围拖曳)。仅当我单击表单空白时(例如,边距/填充区域。如何呈现控件(比如标签),使其不捕获鼠标事件,而是将其传递给基础表单元素?换句话说,我想单击此标签元素并拖动表单。
我能想到的最接近的是pointer-events: none
中的CSS
。
这是我用来使表格可移动的powershell代码:
function makeFormDraggable {
param($form)
Add-Type '
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
public class User32{
//const and dll functions for moving form
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
}
'
$onMouseDown = [System.Windows.Forms.MouseEventHandler] {
#Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
[user32]::ReleaseCapture()
[user32]::SendMessage($form.Handle, [user32]::WM_NCLBUTTONDOWN, [user32]::HT_CAPTION, 0);
}
$form.Add_MouseDown($onMouseDown)
}