으로 Windows 메시지 큐를 지우면 보류중인 클릭을 건너 뛸 수 있습니다. Application.DoEvents();
우리는 (여러 번의 클릭을 방지하고 필요한 경우 대기 커서를 표시) 문제를 해결하기 위해 다음과 같은 사용자 정의 이벤트 클래스를 사용
이
using System;
using System.Windows.Forms;
public sealed class Event {
bool forwarding;
public event EventHandler Action;
void Forward (object o, EventArgs a) {
if ((Action != null) && (!forwarding)) {
forwarding = true;
Cursor cursor = Cursor.Current;
try {
Cursor.Current = Cursors.WaitCursor;
Action(o, a);
} finally {
Cursor.Current = cursor;
Application.DoEvents();
forwarding = false;
}
}
}
public EventHandler Handler {
get {
return new EventHandler(Forward);
}
}
}
당신은 그것을 다음 예제와 함께 작동하는지 확인할 수 있습니다 (콘솔 출력은 클릭 HandleClick)가 종료 된 경우 :
using System;
using System.Threading;
using System.Windows.Forms;
class Program {
static void HandleClick (object o, EventArgs a) {
Console.WriteLine("Click");
Thread.Sleep(1000);
}
static void Main() {
Form f = new Form();
Button b = new Button();
//b.Click += new EventHandler(HandleClick);
Event e = new Event();
e.Action += new EventHandler(HandleClick);
b.Click += e.Handler;
f.Controls.Add(b);
Application.Run(f);
}
}
는 다음과 같이 문제가 위의 코드를 변경 재현하려면 (콘솔) 지연, 모든 클릭을 출력합니다
b.Click += new EventHandler(HandleClick);
//Event e = new Event();
//e.Action += new EventHandler(HandleClick);
//b.Click += e.Handler;
Event 클래스는 EventHandler 이벤트 (Button, MenuItem, ListView, ...)를 노출하는 모든 컨트롤에 사용할 수 있습니다.
감사합니다, tamberg
좋은 제안, 나에게 시도 할 수있는 몇 가지 다른 팁을 제공합니다. 고맙습니다! – Steve
CF를 사용하여 적절한 투명도를 얻을 수 있지만 P/Invoke를 통해 직사각형 영역을 서로 붙입니다. 별로 예쁘지 않습니다. – Quibblesome