bool isKeyPressed = false; //KeyDown fires many times, possible bug in Eto.Forms ? /// <summary> /// Creates new image display form supporting rectangle creation. /// </summary> /// <param name="title">Window title.</param> /// <param name="setPassingResetEvent">True to set the reset event to passing state, false otherwise.</param> public DrawingRectangleForm(string title = "", bool setPassingResetEvent = true) : base(title) { adorner = new DrawingRectangleAdorner(PictureBox); adorner.OnDrawn = () => { if (OnDrawn != null && !Rectangle.IsEmpty) { OnDrawn(Rectangle); } adorner.Clear(); }; ResetEvent = new ManualResetEvent(setPassingResetEvent); KeyDown += (s, e) => { if (isKeyPressed) { return; } isKeyPressed = true; ResetEvent.Reset(); }; KeyUp += (s, e) => { isKeyPressed = false; ResetEvent.Set(); }; }
bool isKeyPressed = false; //KeyDown fires many times, possible bug in Eto.Forms ? /// <summary> /// Creates new image display form supporting rectangle creation. /// </summary> /// <param name="title">Window title.</param> /// <param name="setPassingResetEvent">True to set the reset event to passing state, false otherwise.</param> public DrawingRectangleForm(string title = "", bool setPassingResetEvent = true) :base(title) { adorner = new DrawingRectangleAdorner(PictureBox); adorner.OnDrawn = () => { if (OnDrawn != null && !Rectangle.IsEmpty) OnDrawn(Rectangle); adorner.Clear(); }; ResetEvent = new ManualResetEvent(setPassingResetEvent); KeyDown += (s, e) => { if (isKeyPressed) return; isKeyPressed = true; ResetEvent.Reset(); }; KeyUp += (s, e) => { isKeyPressed = false; ResetEvent.Set(); }; }