I have a form which has various buttons and panels. I have one button which when pressed runs a check against some values and if the check passes I need the mouse click to fall through the form and hit whatever it is beneath the application window.
What I'm currently doing is after the button is pressed and the check has passed, I set the form to transparent using:
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private int oldWindowLong = 0;
public void SetFormTransparent(IntPtr Handle)
{
oldWindowLong = GetWindowLong(Handle, -20);
SetWindowLong(Handle, -20, Convert.ToInt32(oldWindowLong | 0x80000 | 0x20));
}
public void SetFormNormal(IntPtr Handle)
{
SetWindowLong(Handle, -20, Convert.ToInt32(oldWindowLong | 0x80000));
}
Then I create a 1 millisecond timer, I simulate the mouse click using:
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
And set the form back to normal. This results in a really inconsistent and sometimes slow/unresponsive behavior.
What other options do I have if I want to simulate a mouse click as soon as the button's check has passed?