void Canvas_KeyDown(object sender, KeyEventArgs e) { if (dragging) { return; } if (e.KeyCode == Keys.PageUp) { ImageScale += ScaleIncrement; } if (e.KeyCode == Keys.PageDown) { ImageScale -= ScaleIncrement; } if (e.Control && e.KeyCode == Keys.Z) { commandExecutor.Undo(); } if (e.Control && e.KeyCode == Keys.Y) { commandExecutor.Redo(); } if (e.Control && e.KeyCode == Keys.V) { var roiText = (string)Clipboard.GetData(DataFormats.Text); try { var mousePosition = PointToClient(MousePosition); var offset = NormalizedLocation(mousePosition.X, mousePosition.Y); var roiData = (float[])ArrayConvert.ToArray(roiText, 1, typeof(float)); var center = new Point2f(offset.X, offset.Y); var size = new Size2f(roiData[0], roiData[1]); var roi = new RotatedRect(center, size, 0); var selection = selectedRoi; commandExecutor.Execute( () => AddRegion(roi), () => { regions.Remove(roi); SelectedRegion = selection; }); } catch (ArgumentException) { } catch (InvalidCastException) { } catch (FormatException) { } } if (selectedRoi.HasValue) { if (e.Control && e.KeyCode == Keys.C) { var roi = regions[selectedRoi.Value]; var roiData = new[] { roi.Size.Width, roi.Size.Height }; Clipboard.SetData(DataFormats.Text, ArrayConvert.ToString(roiData)); } if (e.KeyCode == Keys.Delete) { var selection = selectedRoi.Value; var region = regions[selection]; commandExecutor.Execute( () => { regions.RemoveAt(selection); SelectedRegion = null; }, () => { regions.Insert(selection, region); SelectedRegion = selection; }); } } }
void Canvas_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.PageUp) { ImageScale += ScaleIncrement; } if (e.KeyCode == Keys.PageDown) { ImageScale -= ScaleIncrement; } if (e.Control && e.KeyCode == Keys.Z) { commandExecutor.Undo(); } if (e.Control && e.KeyCode == Keys.Y) { commandExecutor.Redo(); } if (e.Control && e.KeyCode == Keys.V) { var roiText = (string)Clipboard.GetData(DataFormats.Text); try { var mousePosition = PointToClient(MousePosition); var offset = NormalizedLocation(mousePosition.X, mousePosition.Y); var roiData = (int[])ArrayConvert.ToArray(roiText, 1, typeof(int)); var roi = new Point[roiData.Length / 2]; for (int i = 0, k = 0; i < roi.Length && k < roiData.Length; i++, k += 2) { roi[i].X = roiData[k + 0] - roiData[0] + offset.X; roi[i].Y = roiData[k + 1] - roiData[1] + offset.Y; } var selection = selectedRoi; commandExecutor.Execute( () => AddRegion(roi), () => { regions.Remove(roi); SelectedRegion = selection; }); } catch (ArgumentException) { } catch (InvalidCastException) { } catch (FormatException) { } } if (selectedRoi.HasValue) { if (e.Control && e.KeyCode == Keys.C) { var roi = regions[selectedRoi.Value]; var roiData = new int[roi.Length * 2]; for (int i = 0, k = 0; i < roi.Length && k < roiData.Length; i++, k += 2) { roiData[k + 0] = roi[i].X; roiData[k + 1] = roi[i].Y; } Clipboard.SetData(DataFormats.Text, ArrayConvert.ToString(roiData)); } if (e.KeyCode == Keys.Delete) { var selection = selectedRoi.Value; var region = regions[selection]; commandExecutor.Execute( () => { regions.RemoveAt(selection); SelectedRegion = null; }, () => { regions.Insert(selection, region); SelectedRegion = selection; }); } } }