public static void ColorField(string name, Color value, Action <Color> setColor) { GUILayout.BeginHorizontal(); GUILayout.Label(name + ":", GUILayout.Width(_nameWidth)); if (WinFormsCompatible) { if (Button(value.ToString())) { var colorForm = new ColorPickerForm(); colorForm.Color = value; colorForm.Show(); colorForm.ColorChanged += (s, a) => { if (setColor != null) { setColor.Invoke(colorForm.Color); } }; } } #if UNITY_EDITOR else { var colorBuffer = UnityEditor.EditorGUILayout.ColorField(value.ToUnityColor(), GUILayout.Width(_contentWidth)).ToColor(); if (colorBuffer != value && setColor != null) { setColor.Invoke(colorBuffer); } } #endif GUILayout.EndHorizontal(); }
private void Swatch_MouseDoubleClick(object sender, MouseEventArgs e) { ColorPickerForm form = new ColorPickerForm(); form.ColorObject = this._color; //.ColorRGBA; form.ColorChanged += new EventHandler(form_ColorChanged); form.Show(); }
public static void ColorField(string name, Color value, Action <Color> setColor) { UnityEngine.GUILayout.BeginHorizontal(); UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth)); Color colorBuffer = value; if (WinFormsCompatible) { if (Button(value.ToString())) { ColorPicker colorPicker = new ColorPicker(); ColorPickerForm colorForm = new ColorPickerForm(colorPicker); colorForm.Color = value; colorForm.Show(); colorForm.ColorChanged += (s, a) => { if (setColor != null) { setColor.Invoke(colorForm.Color); } }; } } #if UNITY_EDITOR else { colorBuffer = System.Drawing.Color.FromUColor(UnityEditor.EditorGUILayout.ColorField(value.ToUColor(), UnityEngine.GUILayout.Width(_contentWidth))); if (colorBuffer != value && setColor != null) { setColor.Invoke(colorBuffer); } } #endif UnityEngine.GUILayout.EndHorizontal(); }
protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); switch (e.Button) { case MouseButtons.Left: Series.visible = !Series.visible; var highcharts = Parent as Highchart; if (highcharts != null) { highcharts.UpdatePlot(); // Update plot min and max values range. } break; case MouseButtons.Right: var itemColor = new ToolStripMenuItem(Highchart.textLegendMenu_Color); itemColor.Click += (sender, args) => { var form = new ColorPickerForm(); form.Color = Series.color; form.ColorChanged += (sender2, args2) => Series.color = form.Color; form.ShowDialog(); }; var context = new ContextMenuStrip(); context.Items.Add(itemColor); context.Show(null, MousePosition); break; } }
private void RectangleAnnotate_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.D1) { Mode = RegionAnnotateMode.Capture; } else if (e.KeyCode == Keys.D2) { Mode = RegionAnnotateMode.Rectangle; } else if (e.KeyCode == Keys.D3) { Mode = RegionAnnotateMode.Pen; } else if (e.KeyCode == Keys.ShiftKey && IsDrawingMode) { try { isBusy = true; Options.DrawingPenColor = ColorPickerForm.GetColor(Options.DrawingPenColor); } finally { isBusy = false; } } else if (e.KeyCode == Keys.F1) { Options.ShowTips = !Options.ShowTips; } }
public static void ShowScreenColorPickerDialog(RegionCaptureOptions options) { Color color = Color.Red; ColorPickerForm colorPickerForm = new ColorPickerForm(color, true); colorPickerForm.EnableScreenColorPickerButton(() => GetPointInfo(options)); colorPickerForm.Show(); }
private void foregroundBrushColorToolStripButton_Click(object sender, EventArgs e) { var colorPickerForm = new ColorPickerForm(foregroundBrushColorToolStripButton.BackColor); if(colorPickerForm.ShowDialog() == DialogResult.OK) { foregroundBrushColorToolStripButton.BackColor = colorPickerForm.CurrentColor; } }
public void ShowColorDialog() { using (ColorPickerForm dialogColor = new ColorPickerForm(Color)) { if (dialogColor.ShowDialog() == DialogResult.OK) { Color = dialogColor.NewColor; } } }
private void tsmiSecondColor_Click(object sender, EventArgs e) { ColorPickerForm.PickColor(Options.Color2, out Color newColor, this); Options.Color2 = newColor; if (tsmiSecondColor.Image != null) { tsmiSecondColor.Image.Dispose(); } tsmiSecondColor.Image = ImageHelpers.CreateColorPickerIcon(Options.Color2, new Rectangle(0, 0, 16, 16)); }
internal void ColorPicker_Click(object sender, EventArgs e) { ColorPickerForm cpf = new ColorPickerForm(); cpf.FormClosing += Childform_Closing; cpf.TopMost = SettingsManager.MainFormSettings.Always_On_Top; cpf.StartPosition = FormStartPosition.CenterScreen; cpf.Show(); _childrenHandles.Add(cpf); }
public static Color AskChooseColor(Color initColor) { using (ColorPickerForm f = new ColorPickerForm()) { f.TopMost = true; f.UpdateColors(initColor); f.ShowDialog(); return(f.GetCurrentColor()); } }
void ColorChip_Click(object sender, EventArgs e) { if (this._autoOpenEditor) { ColorPickerForm form = new ColorPickerForm(); form.ColorObject = this.ColorObject; form.MdiParent = ((System.Windows.Forms.Form)this.TopLevelControl).MdiParent; form.ColorChanged += new EventHandler(form_ColorChanged); form.ShowDialog(); } }
private void btnColorDialog_Click(object sender, EventArgs e) { using (ColorPickerForm dialogColor = new ColorPickerForm(Color.FromArgb(tbRed.Value, tbGreen.Value, tbBlue.Value))) { if (dialogColor.ShowDialog() == DialogResult.OK) { Color color = dialogColor.NewColor; tbRed.Value = color.R; tbGreen.Value = color.G; tbBlue.Value = color.B; DrawRedGreenBlue(); } } }
public static Color GetColor(Color currentColor) { using (ColorPickerForm dialog = new ColorPickerForm(currentColor)) { dialog.rbSaturation.Checked = true; if (dialog.ShowDialog() == DialogResult.OK) { return dialog.NewColor; } } return currentColor; }
private void gamutWarningColorButton_Click(object sender, EventArgs e) { using (ColorPickerForm form = new ColorPickerForm("Choose a gamut warning color:")) { form.BackColor = BackColor; form.ForeColor = ForeColor; form.SetDefaultColor(this.gamutWarningColorButton.Value); if (form.ShowDialog(this) == DialogResult.OK) { this.gamutWarningColorButton.Value = form.UserPrimaryColor; UpdateConfigToken(); } } }
/// <summary> /// Shows the color picker dialog, with the specified initial color. /// </summary> /// <param name="prompt">The prompt.</param> /// <param name="red">The red component of the initial color.</param> /// <param name="green">The green component of the initial color.</param> /// <param name="blue">The blue component of the initial color.</param> /// <returns>The user's chosen color; or null if the user canceled the dialog.</returns> public static ColorBgra?ShowColorPickerDialog(string prompt, short red, short green, short blue) { ColorBgra?chosenColor = null; using (ColorPickerForm form = new ColorPickerForm(prompt)) { form.BackColor = formBackColor; form.ForeColor = formForeColor; form.SetDefaultColor(red, green, blue); if (form.ShowDialog() == DialogResult.OK) { chosenColor = form.UserPrimaryColor; } } return(chosenColor); }
public static void ShowScreenColorPickerDialog(RegionCaptureOptions options, bool checkClipboard = true) { Color color = Color.Red; if (checkClipboard) { string text = ClipboardHelpers.GetText(true); if (!string.IsNullOrEmpty(text) && ColorHelpers.ParseColor(text, out Color clipboardColor)) { color = clipboardColor; } } ColorPickerForm colorPickerForm = new ColorPickerForm(color, true); colorPickerForm.EnableScreenColorPickerButton(() => GetPointInfo(options)); colorPickerForm.Show(); }
private void OnButtonMdiOnClick(object sender, EventArgs args) { var form = new Form(); form.IsMdiContainer = true; form.Text = "Mdi Form"; form.Size = new Size(640, 480); form.SizeGripStyle = SizeGripStyle.Show; form.Show(); var formTree = new Form(); formTree.BackColor = Color.White; formTree.Text = "Inner Form"; formTree.MdiParent = form; var tree = new TreeView(); tree.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top; tree.BackColor = Color.White; tree.BorderStyle = BorderStyle.None; tree.Location = new Point(0, formTree.uwfHeaderHeight); tree.Size = new Size(formTree.Width, formTree.Height - formTree.uwfHeaderHeight - 16); for (int i = 0; i < 50; i++) { tree.Nodes.Add("test node " + i); } tree.Refresh(); formTree.Controls.Add(tree); formTree.SizeGripStyle = SizeGripStyle.Show; formTree.Show(); var formColor = new ColorPickerForm(); formColor.MdiParent = form; formColor.Color = tree.BackColor; formColor.Show(); formColor.ColorChanged += (o, eventArgs) => tree.BackColor = formColor.Color; }
protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); switch (e.Button) { case MouseButtons.Left: seriesEnabled = !seriesEnabled; Series.visible = seriesEnabled; if (Parent != null) ((Highchart)Parent).RecalcCategories(); break; case MouseButtons.Right: var itemColor = new ToolStripMenuItem(Highchart.textLegendMenu_Color); itemColor.Click += (sender, args) => { var form = new ColorPickerForm(); form.Color = Series.color; form.ColorChanged += (sender2, args2) => Series.color = form.Color; form.ShowDialog(); }; var itemType = new ToolStripMenuItem(Highchart.textLegendMenu_Type); var seriesTypes = Highchart.textLegendMenu_TypeNames; for (int i = 0; i < seriesTypes.Length; i++) { int index = i; var item = new ToolStripMenuItem(seriesTypes[i]); item.Click += (s, a) => { Series.type = (SeriesTypes)index; }; itemType.DropDownItems.Add(item); } var context = new ContextMenuStrip(); context.Items.Add(itemColor); context.Items.Add(itemType); context.Show(null, MousePosition); break; } }
private void RectangleAnnotate_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ControlKey) { isDrawingMode = !isDrawingMode; CursorShown = !isDrawingMode; } else if (e.KeyCode == Keys.ShiftKey && isDrawingMode) { isDrawingMode = false; try { Options.DrawingPenColor = ColorPickerForm.GetColor(Options.DrawingPenColor); } finally { CursorShown = false; isDrawingMode = true; } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (value.GetType() != typeof(Color)) { return(value); } IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (svc != null) { Color color = (Color)value; using (ColorPickerForm form = new ColorPickerForm(color)) { if (svc.ShowDialog(form) == DialogResult.OK) { return(form.GetCurrentColor().ARGB.ToColor()); } } } return(value); }
private void designView_DoubleClick(object sender, EventArgs e) { if (designView.SelectedItems.Count < 1) return; ListViewItem item = designView.SelectedItems[0]; object value = item.Tag; if (value != null && value is Color) { using (ColorPickerForm frm = new ColorPickerForm()) { frm.SelectedColor = (Color)value; if (frm.ShowDialog() == DialogResult.OK) { object val = frm.SelectedColor; item.SubItems[1].Name = val.ToString(); item.SubItems[1].Text = val.ToString(); item.Tag = val; } } } else if (value != null && value is Font) { using (FontDialog dlg = new FontDialog()) { dlg.Font = value as Font; dlg.FontMustExist = true; dlg.ShowColor = false; if (dlg.ShowDialog() == DialogResult.OK) { object val = dlg.Font; item.SubItems[1].Name = val.ToString(); item.SubItems[1].Text = val.ToString(); item.Tag = val; } } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (value.GetType() != typeof(Color)) { return value; } IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (svc != null) { Color color = (Color)value; using (ColorPickerForm form = new ColorPickerForm(color)) { if (svc.ShowDialog(form) == DialogResult.OK) { return (Color)form.NewColor; } } } return value; }
public void Handler(Control parent, Point menuLocation, int alternativeLocation, IDisposable disposeWhenDone) { try { ColorPickerForm form = new ColorPickerForm(); form.Color = ColorizedResources.AppColor; form.ColorSelected += new ColorSelectedEventHandler(form_ColorSelected); form.Closed += new EventHandler(form_Closed); form.StartPosition = FormStartPosition.Manual; Point startLocation = CommandBarButtonLightweightControl.PositionMenu(menuLocation, alternativeLocation, form.Size); form.Location = startLocation; _disposeWhenDone = disposeWhenDone; IMiniFormOwner miniFormOwner = parent.FindForm() as IMiniFormOwner; if (miniFormOwner != null) form.FloatAboveOwner(miniFormOwner); form.Show(); } catch { disposeWhenDone.Dispose(); throw; } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); ColorPickerForm form = new ColorPickerForm(); form.Color = Color; form.ColorSelected += new ColorSelectedEventHandler(form_ColorSelected); form.Closed += new EventHandler(form_Closed); form.TopMost = true; form.StartPosition = FormStartPosition.Manual; Point p = PointToScreen(new Point(0, Height)); form.Location = p; form.Show(); m_pressed = true; Invalidate(); }
private void CreateMenu() { menuForm = new Form() { AutoScaleDimensions = new SizeF(6F, 13F), AutoScaleMode = AutoScaleMode.Font, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ClientSize = new Size(759, 509), FormBorderStyle = FormBorderStyle.None, Location = new Point(200, 200), ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, Text = "RegionCaptureFormMenu" }; menuForm.SuspendLayout(); tsMain = new ToolStripEx() { AutoSize = true, CanOverflow = false, ClickThrough = true, Dock = DockStyle.None, GripStyle = ToolStripGripStyle.Hidden, Location = new Point(0, 0), MinimumSize = new Size(300, 30), Padding = new Padding(0, 0, 0, 0), Renderer = new CustomToolStripProfessionalRenderer(), TabIndex = 0 }; tsMain.SuspendLayout(); menuForm.Controls.Add(tsMain); ToolStripLabel tslDragLeft = new ToolStripLabel() { DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(0), Padding = new Padding(2) }; tslDragLeft.MouseDown += (sender, e) => { NativeMethods.ReleaseCapture(); NativeMethods.DefWindowProc(menuForm.Handle, (uint)WindowsMessages.SYSCOMMAND, (UIntPtr)NativeConstants.MOUSE_MOVE, IntPtr.Zero); }; tsMain.Items.Add(tslDragLeft); #region Editor mode if (form.Mode == RegionCaptureMode.Editor) { ToolStripButton tsbCompleteEdit = new ToolStripButton("Run after capture tasks"); tsbCompleteEdit.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCompleteEdit.Image = Resources.tick; tsbCompleteEdit.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateRunAfterCaptureTasks); tsMain.Items.Add(tsbCompleteEdit); ToolStripButton tsbSaveImage = new ToolStripButton("Save image"); tsbSaveImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImage.Enabled = !string.IsNullOrEmpty(form.ImageFilePath); tsbSaveImage.Image = Resources.disk_black; tsbSaveImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImage); tsMain.Items.Add(tsbSaveImage); ToolStripButton tsbSaveImageAs = new ToolStripButton("Save image as..."); tsbSaveImageAs.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImageAs.Image = Resources.disks_black; tsbSaveImageAs.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImageAs); tsMain.Items.Add(tsbSaveImageAs); ToolStripButton tsbCopyImage = new ToolStripButton("Copy image to clipboard"); tsbCopyImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCopyImage.Image = Resources.clipboard; tsbCopyImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateCopyImage); tsMain.Items.Add(tsbCopyImage); ToolStripButton tsbUploadImage = new ToolStripButton("Upload image"); tsbUploadImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbUploadImage.Image = Resources.drive_globe; tsbUploadImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateUploadImage); tsMain.Items.Add(tsbUploadImage); ToolStripButton tsbPrintImage = new ToolStripButton("Print image..."); tsbPrintImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbPrintImage.Image = Resources.printer; tsbPrintImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotatePrintImage); tsMain.Items.Add(tsbPrintImage); tsMain.Items.Add(new ToolStripSeparator()); } #endregion Editor mode #region Tools foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>()) { if (form.Mode == RegionCaptureMode.Editor) { if (IsShapeTypeRegion(shapeType)) { continue; } } else if (shapeType == ShapeType.DrawingRectangle) { tsMain.Items.Add(new ToolStripSeparator()); } ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription()); tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image; Image img = null; switch (shapeType) { case ShapeType.RegionRectangle: img = Resources.layer_shape_region; break; case ShapeType.RegionRoundedRectangle: img = Resources.layer_shape_round_region; break; case ShapeType.RegionEllipse: img = Resources.layer_shape_ellipse_region; break; case ShapeType.RegionFreehand: img = Resources.layer_shape_polygon; break; case ShapeType.DrawingRectangle: img = Resources.layer_shape; break; case ShapeType.DrawingRoundedRectangle: img = Resources.layer_shape_round; break; case ShapeType.DrawingEllipse: img = Resources.layer_shape_ellipse; break; case ShapeType.DrawingFreehand: img = Resources.layer_shape_curve; break; case ShapeType.DrawingLine: img = Resources.layer_shape_line; break; case ShapeType.DrawingArrow: img = Resources.layer_shape_arrow; break; case ShapeType.DrawingText: img = Resources.layer_shape_text; break; case ShapeType.DrawingSpeechBalloon: img = Resources.balloon_box_left; break; case ShapeType.DrawingStep: img = Resources.counter_reset; break; case ShapeType.DrawingImage: img = Resources.image; break; case ShapeType.EffectBlur: img = Resources.layer_shade; break; case ShapeType.EffectPixelate: img = Resources.grid; break; case ShapeType.EffectHighlight: img = Resources.highlighter_text; break; } tsbShapeType.Image = img; tsbShapeType.Checked = shapeType == CurrentShapeType; tsbShapeType.Tag = shapeType; tsbShapeType.MouseDown += (sender, e) => { tsbShapeType.RadioCheck(); CurrentShapeType = shapeType; }; tsMain.Items.Add(tsbShapeType); } #endregion Tools #region Selected object tsMain.Items.Add(new ToolStripSeparator()); tsddbShapeOptions = new ToolStripDropDownButton("Shape options"); tsddbShapeOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbShapeOptions.Image = Resources.layer__pencil; tsMain.Items.Add(tsddbShapeOptions); tsmiBorderColor = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Border_color___); tsmiBorderColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color borderColor; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { borderColor = AnnotationOptions.TextBorderColor; } else if (shapeType == ShapeType.DrawingStep) { borderColor = AnnotationOptions.StepBorderColor; } else { borderColor = AnnotationOptions.BorderColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderColor = dialogColor.NewColor; } else { AnnotationOptions.BorderColor = dialogColor.NewColor; } UpdateMenu(); UpdateCurrentShape(); UpdateCursor(); } } ResumeForm(); }; tsddbShapeOptions.DropDownItems.Add(tsmiBorderColor); tslnudBorderSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Border_size_); tslnudBorderSize.Content.Minimum = 0; tslnudBorderSize.Content.Maximum = 20; tslnudBorderSize.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; int borderSize = (int)tslnudBorderSize.Content.Value; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderSize = borderSize; } else { AnnotationOptions.BorderSize = borderSize; } UpdateCurrentShape(); UpdateCursor(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBorderSize); tsmiFillColor = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Fill_color___); tsmiFillColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color fillColor; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { fillColor = AnnotationOptions.TextFillColor; } else if (shapeType == ShapeType.DrawingStep) { fillColor = AnnotationOptions.StepFillColor; } else { fillColor = AnnotationOptions.FillColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextFillColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepFillColor = dialogColor.NewColor; } else { AnnotationOptions.FillColor = dialogColor.NewColor; } UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsddbShapeOptions.DropDownItems.Add(tsmiFillColor); tslnudCornerRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_); tslnudCornerRadius.Content.Minimum = 0; tslnudCornerRadius.Content.Maximum = 150; tslnudCornerRadius.Content.Increment = 3; tslnudCornerRadius.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; if (shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle) { AnnotationOptions.RoundedRectangleRadius = (int)tslnudCornerRadius.Content.Value; } else if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextCornerRadius = (int)tslnudCornerRadius.Content.Value; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudCornerRadius); tslnudBlurRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Blur_radius_); tslnudBlurRadius.Content.Minimum = 2; tslnudBlurRadius.Content.Maximum = 100; tslnudBlurRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBlurRadius); tslnudPixelateSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Pixel_size_); tslnudPixelateSize.Content.Minimum = 2; tslnudPixelateSize.Content.Maximum = 100; tslnudPixelateSize.Content.ValueChanged = (sender, e) => { AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudPixelateSize); tsmiHighlightColor = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Highlight_color___); tsmiHighlightColor.Click += (sender, e) => { PauseForm(); using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { AnnotationOptions.HighlightColor = dialogColor.NewColor; UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsddbShapeOptions.DropDownItems.Add(tsmiHighlightColor); tsbDeleteSelected = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Delete_selected_object); tsbDeleteSelected.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbDeleteSelected.Image = Resources.layer__minus; tsbDeleteSelected.MouseDown += (sender, e) => DeleteCurrentShape(); tsMain.Items.Add(tsbDeleteSelected); tsbDeleteAll = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Delete_all_objects); tsbDeleteAll.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbDeleteAll.Image = Resources.eraser; tsbDeleteAll.MouseDown += (sender, e) => DeleteAllShapes(); tsMain.Items.Add(tsbDeleteAll); #endregion Selected object #region Capture if (form.Mode != RegionCaptureMode.Editor) { tsMain.Items.Add(new ToolStripSeparator()); ToolStripButton tsbFullscreenCapture = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Capture_fullscreen); tsbFullscreenCapture.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbFullscreenCapture.Image = Resources.layer_fullscreen; tsbFullscreenCapture.MouseDown += (sender, e) => form.Close(RegionResult.Fullscreen); tsMain.Items.Add(tsbFullscreenCapture); ToolStripButton tsbActiveMonitorCapture = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Capture_active_monitor); tsbActiveMonitorCapture.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbActiveMonitorCapture.Image = Resources.monitor; tsbActiveMonitorCapture.MouseDown += (sender, e) => form.Close(RegionResult.ActiveMonitor); tsMain.Items.Add(tsbActiveMonitorCapture); ToolStripDropDownButton tsddbMonitorCapture = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Capture_monitor); tsddbMonitorCapture.HideImageMargin(); tsddbMonitorCapture.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbMonitorCapture.Image = Resources.monitor_window; tsMain.Items.Add(tsddbMonitorCapture); tsddbMonitorCapture.DropDownItems.Clear(); Screen[] screens = Screen.AllScreens; for (int i = 0; i < screens.Length; i++) { Screen screen = screens[i]; ToolStripMenuItem tsmi = new ToolStripMenuItem(string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height)); int index = i; tsmi.MouseDown += (sender, e) => { form.MonitorIndex = index; form.Close(RegionResult.Monitor); }; tsddbMonitorCapture.DropDownItems.Add(tsmi); } } #endregion Capture #region Options if (form.Mode != RegionCaptureMode.Editor) { tsMain.Items.Add(new ToolStripSeparator()); ToolStripDropDownButton tsddbOptions = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Options); tsddbOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbOptions.Image = Resources.gear; tsMain.Items.Add(tsddbOptions); tsmiQuickCrop = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Multi_region_mode); tsmiQuickCrop.Checked = !Config.QuickCrop; tsmiQuickCrop.CheckOnClick = true; tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked; tsddbOptions.DropDownItems.Add(tsmiQuickCrop); ToolStripMenuItem tsmiTips = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_tips); tsmiTips.Checked = Config.ShowTips; tsmiTips.CheckOnClick = true; tsmiTips.Click += (sender, e) => Config.ShowTips = tsmiTips.Checked; tsddbOptions.DropDownItems.Add(tsmiTips); ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_position_and_size_info); tsmiShowInfo.Checked = Config.ShowInfo; tsmiShowInfo.CheckOnClick = true; tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked; tsddbOptions.DropDownItems.Add(tsmiShowInfo); ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_magnifier); tsmiShowMagnifier.Checked = Config.ShowMagnifier; tsmiShowMagnifier.CheckOnClick = true; tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiShowMagnifier); ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Square_shape_magnifier); tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier; tsmiUseSquareMagnifier.CheckOnClick = true; tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiUseSquareMagnifier); ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_count_); tslnudMagnifierPixelCount.Content.Minimum = RegionCaptureOptions.MagnifierPixelCountMinimum; tslnudMagnifierPixelCount.Content.Maximum = RegionCaptureOptions.MagnifierPixelCountMaximum; tslnudMagnifierPixelCount.Content.Increment = 2; tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount; tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelCount); ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_size_); tslnudMagnifierPixelSize.Content.Minimum = RegionCaptureOptions.MagnifierPixelSizeMinimum; tslnudMagnifierPixelSize.Content.Maximum = RegionCaptureOptions.MagnifierPixelSizeMaximum; tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize; tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelSize); ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_screen_wide_crosshair); tsmiShowCrosshair.Checked = Config.ShowCrosshair; tsmiShowCrosshair.CheckOnClick = true; tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked; tsddbOptions.DropDownItems.Add(tsmiShowCrosshair); ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Fixed_size_region_mode); tsmiFixedSize.Checked = Config.IsFixedSize; tsmiFixedSize.CheckOnClick = true; tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked; tsddbOptions.DropDownItems.Add(tsmiFixedSize); ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Width_, Resources.ShapeManager_CreateContextMenu_Height_); tslnudFixedSize.Content.Minimum = 10; tslnudFixedSize.Content.Maximum = 10000; tslnudFixedSize.Content.Increment = 10; tslnudFixedSize.Content.Value = Config.FixedSize.Width; tslnudFixedSize.Content.Value2 = Config.FixedSize.Height; tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2); tsddbOptions.DropDownItems.Add(tslnudFixedSize); ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_FPS); tsmiShowFPS.Checked = Config.ShowFPS; tsmiShowFPS.CheckOnClick = true; tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked; tsddbOptions.DropDownItems.Add(tsmiShowFPS); } #endregion Options ToolStripLabel tslDragRight = new ToolStripLabel() { Alignment = ToolStripItemAlignment.Right, DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(0), Padding = new Padding(2) }; tslDragRight.MouseDown += (sender, e) => { NativeMethods.ReleaseCapture(); NativeMethods.DefWindowProc(menuForm.Handle, (uint)WindowsMessages.SYSCOMMAND, (UIntPtr)NativeConstants.MOUSE_MOVE, IntPtr.Zero); }; tsMain.Items.Add(tslDragRight); tsMain.ResumeLayout(false); tsMain.PerformLayout(); menuForm.ResumeLayout(false); menuForm.Show(form); Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenBounds0Based(); if (tsMain.Width < rectActiveScreen.Width) { menuForm.Location = new Point(rectActiveScreen.X + rectActiveScreen.Width / 2 - tsMain.Width / 2, rectActiveScreen.Y + 20); menuForm.LocationChanged += (sender, e) => { Rectangle rectMenu = menuForm.Bounds; Rectangle rectScreen = CaptureHelpers.GetScreenBounds(); Point pos = rectMenu.Location; if (rectMenu.X < rectScreen.X) { pos.X = rectScreen.X; } else if (rectMenu.Right > rectScreen.Right) { pos.X = rectScreen.Right - rectMenu.Width; } if (rectMenu.Y < rectScreen.Y) { pos.Y = rectScreen.Y; } else if (rectMenu.Bottom > rectScreen.Bottom) { pos.Y = rectScreen.Bottom - rectMenu.Height; } if (pos != rectMenu.Location) { menuForm.Location = pos; } }; } else { menuForm.Location = rectActiveScreen.Location; } form.Activate(); UpdateMenu(); CurrentShapeTypeChanged += shapeType => UpdateMenu(); CurrentShapeChanged += shape => UpdateMenu(); }
private void CreateContextMenu() { cmsContextMenu = new ContextMenuStrip(form.components); cmsContextMenu.Renderer = new ToolStripCheckedBoldRenderer(); cmsContextMenu.IgnoreSeparatorClick(); cmsContextMenu.PreviewKeyDown += (sender, e) => { if (e.KeyCode == Keys.Escape) { e.IsInputKey = true; } }; cmsContextMenu.KeyUp += (sender, e) => { if (e.KeyCode == Keys.Escape) { cmsContextMenu.Close(); } }; #region Main ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture"); tsmiCancelCapture.Image = Resources.prohibition; tsmiCancelCapture.Click += (sender, e) => form.Close(RegionResult.Close); cmsContextMenu.Items.Add(tsmiCancelCapture); ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close menu"); tsmiCloseMenu.Image = Resources.cross; tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close(); cmsContextMenu.Items.Add(tsmiCloseMenu); #endregion Main #region Selected object tssObjectOptions = new ToolStripSeparator(); cmsContextMenu.Items.Add(tssObjectOptions); tsmiDeleteSelected = new ToolStripMenuItem("Delete selected object"); tsmiDeleteSelected.Image = Resources.layer__minus; tsmiDeleteSelected.Click += (sender, e) => DeleteCurrentShape(); cmsContextMenu.Items.Add(tsmiDeleteSelected); tsmiDeleteAll = new ToolStripMenuItem("Delete all objects"); tsmiDeleteAll.Image = Resources.minus; tsmiDeleteAll.Click += (sender, e) => ClearAll(); cmsContextMenu.Items.Add(tsmiDeleteAll); #endregion Selected object #region Tools cmsContextMenu.Items.Add(new ToolStripSeparator()); foreach (ShapeType shapeType in Helpers.GetEnums <ShapeType>()) { ToolStripMenuItem tsmiShapeType = new ToolStripMenuItem(shapeType.GetLocalizedDescription()); Image img = null; switch (shapeType) { case ShapeType.RegionRectangle: img = Resources.layer_shape_region; break; case ShapeType.RegionRoundedRectangle: img = Resources.layer_shape_round_region; break; case ShapeType.RegionEllipse: img = Resources.layer_shape_ellipse_region; break; case ShapeType.DrawingRectangle: img = Resources.layer_shape; break; case ShapeType.DrawingRoundedRectangle: img = Resources.layer_shape_round; break; case ShapeType.DrawingEllipse: img = Resources.layer_shape_ellipse; break; case ShapeType.DrawingLine: img = Resources.layer_shape_line; break; case ShapeType.DrawingArrow: img = Resources.layer_shape_arrow; break; case ShapeType.DrawingText: img = Resources.layer_shape_text; break; case ShapeType.DrawingStep: img = Resources.counter_reset; break; case ShapeType.DrawingBlur: img = Resources.layer_shade; break; case ShapeType.DrawingPixelate: img = Resources.grid; break; case ShapeType.DrawingHighlight: img = Resources.highlighter_text; break; } tsmiShapeType.Image = img; tsmiShapeType.Checked = shapeType == CurrentShapeType; tsmiShapeType.Tag = shapeType; tsmiShapeType.Click += (sender, e) => { tsmiShapeType.RadioCheck(); CurrentShapeType = shapeType; }; cmsContextMenu.Items.Add(tsmiShapeType); } #endregion Tools #region Shape options tssShapeOptions = new ToolStripSeparator(); cmsContextMenu.Items.Add(tssShapeOptions); tsmiBorderColor = new ToolStripMenuItem("Border color..."); tsmiBorderColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color borderColor; if (shapeType == ShapeType.DrawingText) { borderColor = AnnotationOptions.TextBorderColor; } else if (shapeType == ShapeType.DrawingStep) { borderColor = AnnotationOptions.StepBorderColor; } else { borderColor = AnnotationOptions.BorderColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextBorderColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderColor = dialogColor.NewColor; } else { AnnotationOptions.BorderColor = dialogColor.NewColor; } UpdateContextMenu(); UpdateCurrentShape(); } } ResumeForm(); }; cmsContextMenu.Items.Add(tsmiBorderColor); tslnudBorderSize = new ToolStripLabeledNumericUpDown("Border size:"); tslnudBorderSize.Content.Minimum = 0; tslnudBorderSize.Content.Maximum = 20; tslnudBorderSize.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; int borderSize = (int)tslnudBorderSize.Content.Value; if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderSize = borderSize; } else { AnnotationOptions.BorderSize = borderSize; } UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudBorderSize); tsmiFillColor = new ToolStripMenuItem("Fill color..."); tsmiFillColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color fillColor; if (shapeType == ShapeType.DrawingText) { fillColor = AnnotationOptions.TextFillColor; } else if (shapeType == ShapeType.DrawingStep) { fillColor = AnnotationOptions.StepFillColor; } else { fillColor = AnnotationOptions.FillColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextFillColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepFillColor = dialogColor.NewColor; } else { AnnotationOptions.FillColor = dialogColor.NewColor; } UpdateContextMenu(); UpdateCurrentShape(); } } ResumeForm(); }; cmsContextMenu.Items.Add(tsmiFillColor); tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown("Corner radius:"); tslnudRoundedRectangleRadius.Content.Minimum = 0; tslnudRoundedRectangleRadius.Content.Maximum = 150; tslnudRoundedRectangleRadius.Content.Increment = 3; tslnudRoundedRectangleRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.Content.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius); tslnudBlurRadius = new ToolStripLabeledNumericUpDown("Blur radius:"); tslnudBlurRadius.Content.Minimum = 2; tslnudBlurRadius.Content.Maximum = 100; tslnudBlurRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudBlurRadius); tslnudPixelateSize = new ToolStripLabeledNumericUpDown("Pixel size:"); tslnudPixelateSize.Content.Minimum = 2; tslnudPixelateSize.Content.Maximum = 100; tslnudPixelateSize.Content.ValueChanged = (sender, e) => { AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudPixelateSize); tsmiHighlightColor = new ToolStripMenuItem("Highlight color..."); tsmiHighlightColor.Click += (sender, e) => { PauseForm(); using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { AnnotationOptions.HighlightColor = dialogColor.NewColor; UpdateContextMenu(); UpdateCurrentShape(); } } ResumeForm(); }; cmsContextMenu.Items.Add(tsmiHighlightColor); #endregion Shape options #region Capture cmsContextMenu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen"); tsmiFullscreenCapture.Image = Resources.layer_fullscreen; tsmiFullscreenCapture.Click += (sender, e) => form.Close(RegionResult.Fullscreen); cmsContextMenu.Items.Add(tsmiFullscreenCapture); ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem("Capture active monitor"); tsmiActiveMonitorCapture.Image = Resources.monitor; tsmiActiveMonitorCapture.Click += (sender, e) => form.Close(RegionResult.ActiveMonitor); cmsContextMenu.Items.Add(tsmiActiveMonitorCapture); ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem("Capture monitor"); tsmiMonitorCapture.HideImageMargin(); tsmiMonitorCapture.Image = Resources.monitor_window; cmsContextMenu.Items.Add(tsmiMonitorCapture); tsmiMonitorCapture.DropDownItems.Clear(); Screen[] screens = Screen.AllScreens; for (int i = 0; i < screens.Length; i++) { Screen screen = screens[i]; ToolStripMenuItem tsmi = new ToolStripMenuItem(string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height)); int index = i; tsmi.Click += (sender, e) => { form.MonitorIndex = index; form.Close(RegionResult.Monitor); }; tsmiMonitorCapture.DropDownItems.Add(tsmi); } #endregion Capture #region Options cmsContextMenu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiOptions = new ToolStripMenuItem("Options"); tsmiOptions.Image = Resources.gear; cmsContextMenu.Items.Add(tsmiOptions); ToolStripMenuItem tsmiQuickCrop = new ToolStripMenuItem("Multi region mode"); tsmiQuickCrop.Checked = !Config.QuickCrop; tsmiQuickCrop.CheckOnClick = true; tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked; tsmiOptions.DropDownItems.Add(tsmiQuickCrop); ToolStripMenuItem tsmiTips = new ToolStripMenuItem("Show tips"); tsmiTips.Checked = Config.ShowTips; tsmiTips.CheckOnClick = true; tsmiTips.Click += (sender, e) => Config.ShowTips = tsmiTips.Checked; tsmiOptions.DropDownItems.Add(tsmiTips); ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem("Show position and size info"); tsmiShowInfo.Checked = Config.ShowInfo; tsmiShowInfo.CheckOnClick = true; tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked; tsmiOptions.DropDownItems.Add(tsmiShowInfo); ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem("Show magnifier"); tsmiShowMagnifier.Checked = Config.ShowMagnifier; tsmiShowMagnifier.CheckOnClick = true; tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked; tsmiOptions.DropDownItems.Add(tsmiShowMagnifier); ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem("Square shape magnifier"); tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier; tsmiUseSquareMagnifier.CheckOnClick = true; tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked; tsmiOptions.DropDownItems.Add(tsmiUseSquareMagnifier); ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown("Magnifier pixel count:"); tslnudMagnifierPixelCount.Content.Minimum = 1; tslnudMagnifierPixelCount.Content.Maximum = 35; tslnudMagnifierPixelCount.Content.Increment = 2; tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount; tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value; tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelCount); ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown("Magnifier pixel size:"); tslnudMagnifierPixelSize.Content.Minimum = 2; tslnudMagnifierPixelSize.Content.Maximum = 30; tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize; tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value; tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelSize); ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem("Show screen wide crosshair"); tsmiShowCrosshair.Checked = Config.ShowCrosshair; tsmiShowCrosshair.CheckOnClick = true; tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked; tsmiOptions.DropDownItems.Add(tsmiShowCrosshair); ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem("Fixed size region mode"); tsmiFixedSize.Checked = Config.IsFixedSize; tsmiFixedSize.CheckOnClick = true; tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked; tsmiOptions.DropDownItems.Add(tsmiFixedSize); ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown("Width:", "Height:"); tslnudFixedSize.Content.Minimum = 5; tslnudFixedSize.Content.Maximum = 10000; tslnudFixedSize.Content.Increment = 10; tslnudFixedSize.Content.Value = Config.FixedSize.Width; tslnudFixedSize.Content.Value2 = Config.FixedSize.Height; tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2); tsmiOptions.DropDownItems.Add(tslnudFixedSize); ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem("Show FPS"); tsmiShowFPS.Checked = Config.ShowFPS; tsmiShowFPS.CheckOnClick = true; tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked; tsmiOptions.DropDownItems.Add(tsmiShowFPS); #endregion Options CurrentShapeTypeChanged += shapeType => UpdateContextMenu(); CurrentShapeChanged += shape => UpdateContextMenu(); }
private void CreateContextMenu() { cmsContextMenu = new ContextMenuStrip(form.components); cmsContextMenu.Renderer = new ToolStripCheckedBoldRenderer(); cmsContextMenu.IgnoreSeparatorClick(); cmsContextMenu.PreviewKeyDown += (sender, e) => { if (e.KeyCode == Keys.Escape) { e.IsInputKey = true; } }; cmsContextMenu.KeyUp += (sender, e) => { if (e.KeyCode == Keys.Escape) { cmsContextMenu.Close(); } }; #region Main ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture"); tsmiCancelCapture.Image = Resources.prohibition; tsmiCancelCapture.Click += (sender, e) => form.Close(RegionResult.Close); cmsContextMenu.Items.Add(tsmiCancelCapture); ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close menu"); tsmiCloseMenu.Image = Resources.cross; tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close(); cmsContextMenu.Items.Add(tsmiCloseMenu); #endregion Main #region Selected object tssObjectOptions = new ToolStripSeparator(); cmsContextMenu.Items.Add(tssObjectOptions); tsmiDeleteSelected = new ToolStripMenuItem("Delete selected object"); tsmiDeleteSelected.Image = Resources.layer__minus; tsmiDeleteSelected.Click += (sender, e) => DeleteCurrentShape(); cmsContextMenu.Items.Add(tsmiDeleteSelected); tsmiDeleteAll = new ToolStripMenuItem("Delete all objects"); tsmiDeleteAll.Image = Resources.minus; tsmiDeleteAll.Click += (sender, e) => ClearAll(); cmsContextMenu.Items.Add(tsmiDeleteAll); #endregion Selected object #region Tools cmsContextMenu.Items.Add(new ToolStripSeparator()); foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>()) { ToolStripMenuItem tsmiShapeType = new ToolStripMenuItem(shapeType.GetLocalizedDescription()); Image img = null; switch (shapeType) { case ShapeType.RegionRectangle: img = Resources.layer_shape_region; break; case ShapeType.RegionRoundedRectangle: img = Resources.layer_shape_round_region; break; case ShapeType.RegionEllipse: img = Resources.layer_shape_ellipse_region; break; case ShapeType.DrawingRectangle: img = Resources.layer_shape; break; case ShapeType.DrawingRoundedRectangle: img = Resources.layer_shape_round; break; case ShapeType.DrawingEllipse: img = Resources.layer_shape_ellipse; break; case ShapeType.DrawingLine: img = Resources.layer_shape_line; break; case ShapeType.DrawingArrow: img = Resources.layer_shape_arrow; break; case ShapeType.DrawingText: img = Resources.layer_shape_text; break; case ShapeType.DrawingStep: img = Resources.counter_reset; break; case ShapeType.DrawingBlur: img = Resources.layer_shade; break; case ShapeType.DrawingPixelate: img = Resources.grid; break; case ShapeType.DrawingHighlight: img = Resources.highlighter_text; break; } tsmiShapeType.Image = img; tsmiShapeType.Checked = shapeType == CurrentShapeType; tsmiShapeType.Tag = shapeType; tsmiShapeType.Click += (sender, e) => { tsmiShapeType.RadioCheck(); CurrentShapeType = shapeType; }; cmsContextMenu.Items.Add(tsmiShapeType); } #endregion Tools #region Shape options tssShapeOptions = new ToolStripSeparator(); cmsContextMenu.Items.Add(tssShapeOptions); tsmiBorderColor = new ToolStripMenuItem("Border color..."); tsmiBorderColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color borderColor; if (shapeType == ShapeType.DrawingText) { borderColor = AnnotationOptions.TextBorderColor; } else if (shapeType == ShapeType.DrawingStep) { borderColor = AnnotationOptions.StepBorderColor; } else { borderColor = AnnotationOptions.BorderColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextBorderColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderColor = dialogColor.NewColor; } else { AnnotationOptions.BorderColor = dialogColor.NewColor; } UpdateContextMenu(); UpdateCurrentShape(); } } ResumeForm(); }; cmsContextMenu.Items.Add(tsmiBorderColor); tslnudBorderSize = new ToolStripLabeledNumericUpDown("Border size:"); tslnudBorderSize.Content.Minimum = 0; tslnudBorderSize.Content.Maximum = 20; tslnudBorderSize.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; int borderSize = (int)tslnudBorderSize.Content.Value; if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderSize = borderSize; } else { AnnotationOptions.BorderSize = borderSize; } UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudBorderSize); tsmiFillColor = new ToolStripMenuItem("Fill color..."); tsmiFillColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color fillColor; if (shapeType == ShapeType.DrawingText) { fillColor = AnnotationOptions.TextFillColor; } else if (shapeType == ShapeType.DrawingStep) { fillColor = AnnotationOptions.StepFillColor; } else { fillColor = AnnotationOptions.FillColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextFillColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepFillColor = dialogColor.NewColor; } else { AnnotationOptions.FillColor = dialogColor.NewColor; } UpdateContextMenu(); UpdateCurrentShape(); } } ResumeForm(); }; cmsContextMenu.Items.Add(tsmiFillColor); tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown("Corner radius:"); tslnudRoundedRectangleRadius.Content.Minimum = 0; tslnudRoundedRectangleRadius.Content.Maximum = 150; tslnudRoundedRectangleRadius.Content.Increment = 3; tslnudRoundedRectangleRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.Content.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius); tslnudBlurRadius = new ToolStripLabeledNumericUpDown("Blur radius:"); tslnudBlurRadius.Content.Minimum = 2; tslnudBlurRadius.Content.Maximum = 100; tslnudBlurRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudBlurRadius); tslnudPixelateSize = new ToolStripLabeledNumericUpDown("Pixel size:"); tslnudPixelateSize.Content.Minimum = 2; tslnudPixelateSize.Content.Maximum = 100; tslnudPixelateSize.Content.ValueChanged = (sender, e) => { AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value; UpdateCurrentShape(); }; cmsContextMenu.Items.Add(tslnudPixelateSize); tsmiHighlightColor = new ToolStripMenuItem("Highlight color..."); tsmiHighlightColor.Click += (sender, e) => { PauseForm(); using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { AnnotationOptions.HighlightColor = dialogColor.NewColor; UpdateContextMenu(); UpdateCurrentShape(); } } ResumeForm(); }; cmsContextMenu.Items.Add(tsmiHighlightColor); #endregion Shape options #region Capture cmsContextMenu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen"); tsmiFullscreenCapture.Image = Resources.layer_fullscreen; tsmiFullscreenCapture.Click += (sender, e) => form.Close(RegionResult.Fullscreen); cmsContextMenu.Items.Add(tsmiFullscreenCapture); ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem("Capture active monitor"); tsmiActiveMonitorCapture.Image = Resources.monitor; tsmiActiveMonitorCapture.Click += (sender, e) => form.Close(RegionResult.ActiveMonitor); cmsContextMenu.Items.Add(tsmiActiveMonitorCapture); ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem("Capture monitor"); tsmiMonitorCapture.HideImageMargin(); tsmiMonitorCapture.Image = Resources.monitor_window; cmsContextMenu.Items.Add(tsmiMonitorCapture); tsmiMonitorCapture.DropDownItems.Clear(); Screen[] screens = Screen.AllScreens; for (int i = 0; i < screens.Length; i++) { Screen screen = screens[i]; ToolStripMenuItem tsmi = new ToolStripMenuItem(string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height)); int index = i; tsmi.Click += (sender, e) => { form.MonitorIndex = index; form.Close(RegionResult.Monitor); }; tsmiMonitorCapture.DropDownItems.Add(tsmi); } #endregion Capture #region Options cmsContextMenu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiOptions = new ToolStripMenuItem("Options"); tsmiOptions.Image = Resources.gear; cmsContextMenu.Items.Add(tsmiOptions); ToolStripMenuItem tsmiQuickCrop = new ToolStripMenuItem("Multi region mode"); tsmiQuickCrop.Checked = !Config.QuickCrop; tsmiQuickCrop.CheckOnClick = true; tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked; tsmiOptions.DropDownItems.Add(tsmiQuickCrop); ToolStripMenuItem tsmiTips = new ToolStripMenuItem("Show tips"); tsmiTips.Checked = Config.ShowTips; tsmiTips.CheckOnClick = true; tsmiTips.Click += (sender, e) => Config.ShowTips = tsmiTips.Checked; tsmiOptions.DropDownItems.Add(tsmiTips); ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem("Show position and size info"); tsmiShowInfo.Checked = Config.ShowInfo; tsmiShowInfo.CheckOnClick = true; tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked; tsmiOptions.DropDownItems.Add(tsmiShowInfo); ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem("Show magnifier"); tsmiShowMagnifier.Checked = Config.ShowMagnifier; tsmiShowMagnifier.CheckOnClick = true; tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked; tsmiOptions.DropDownItems.Add(tsmiShowMagnifier); ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem("Square shape magnifier"); tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier; tsmiUseSquareMagnifier.CheckOnClick = true; tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked; tsmiOptions.DropDownItems.Add(tsmiUseSquareMagnifier); ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown("Magnifier pixel count:"); tslnudMagnifierPixelCount.Content.Minimum = 1; tslnudMagnifierPixelCount.Content.Maximum = 35; tslnudMagnifierPixelCount.Content.Increment = 2; tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount; tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value; tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelCount); ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown("Magnifier pixel size:"); tslnudMagnifierPixelSize.Content.Minimum = 2; tslnudMagnifierPixelSize.Content.Maximum = 30; tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize; tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value; tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelSize); ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem("Show screen wide crosshair"); tsmiShowCrosshair.Checked = Config.ShowCrosshair; tsmiShowCrosshair.CheckOnClick = true; tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked; tsmiOptions.DropDownItems.Add(tsmiShowCrosshair); ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem("Fixed size region mode"); tsmiFixedSize.Checked = Config.IsFixedSize; tsmiFixedSize.CheckOnClick = true; tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked; tsmiOptions.DropDownItems.Add(tsmiFixedSize); ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown("Width:", "Height:"); tslnudFixedSize.Content.Minimum = 5; tslnudFixedSize.Content.Maximum = 10000; tslnudFixedSize.Content.Increment = 10; tslnudFixedSize.Content.Value = Config.FixedSize.Width; tslnudFixedSize.Content.Value2 = Config.FixedSize.Height; tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2); tsmiOptions.DropDownItems.Add(tslnudFixedSize); ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem("Show FPS"); tsmiShowFPS.Checked = Config.ShowFPS; tsmiShowFPS.CheckOnClick = true; tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked; tsmiOptions.DropDownItems.Add(tsmiShowFPS); #endregion Options CurrentShapeTypeChanged += shapeType => UpdateContextMenu(); CurrentShapeChanged += shape => UpdateContextMenu(); }
private void CreateToolbar() { menuForm = new Form() { AutoScaleDimensions = new SizeF(6F, 13F), AutoScaleMode = AutoScaleMode.Font, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ClientSize = new Size(759, 509), FormBorderStyle = FormBorderStyle.None, Location = new Point(200, 200), ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, Text = "ShareX - Region capture menu", TopMost = true }; menuForm.KeyUp += MenuForm_KeyUp; menuForm.LocationChanged += MenuForm_LocationChanged; menuForm.SuspendLayout(); tsMain = new ToolStripEx() { AutoSize = true, CanOverflow = false, ClickThrough = true, Dock = DockStyle.None, GripStyle = ToolStripGripStyle.Hidden, Location = new Point(0, 0), MinimumSize = new Size(10, 30), Padding = new Padding(0, 0, 0, 0), Renderer = new CustomToolStripProfessionalRenderer(), TabIndex = 0, ShowItemToolTips = false }; tsMain.MouseLeave += TsMain_MouseLeave; tsMain.SuspendLayout(); // https://www.medo64.com/2014/01/scaling-toolstrip-with-dpi/ using (Graphics g = menuForm.CreateGraphics()) { double scale = Math.Max(g.DpiX, g.DpiY) / 96.0; double newScale = ((int)Math.Floor(scale * 100) / 25 * 25) / 100.0; if (newScale > 1) { int newWidth = (int)(tsMain.ImageScalingSize.Width * newScale); int newHeight = (int)(tsMain.ImageScalingSize.Height * newScale); tsMain.ImageScalingSize = new Size(newWidth, newHeight); } } menuForm.Controls.Add(tsMain); tslDragLeft = new ToolStripLabel() { DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(2, 0, 2, 0), Padding = new Padding(2) }; tsMain.Items.Add(tslDragLeft); #region Editor mode if (form.Mode == RegionCaptureMode.Editor) { ToolStripButton tsbCompleteEdit = new ToolStripButton("Run after capture tasks"); tsbCompleteEdit.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCompleteEdit.Image = Resources.tick; tsbCompleteEdit.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateRunAfterCaptureTasks); tsMain.Items.Add(tsbCompleteEdit); ToolStripButton tsbSaveImage = new ToolStripButton("Save image"); tsbSaveImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImage.Enabled = !string.IsNullOrEmpty(form.ImageFilePath); tsbSaveImage.Image = Resources.disk_black; tsbSaveImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImage); tsMain.Items.Add(tsbSaveImage); ToolStripButton tsbSaveImageAs = new ToolStripButton("Save image as..."); tsbSaveImageAs.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImageAs.Image = Resources.disks_black; tsbSaveImageAs.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImageAs); tsMain.Items.Add(tsbSaveImageAs); ToolStripButton tsbCopyImage = new ToolStripButton("Copy image to clipboard"); tsbCopyImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCopyImage.Image = Resources.clipboard; tsbCopyImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateCopyImage); tsMain.Items.Add(tsbCopyImage); ToolStripButton tsbUploadImage = new ToolStripButton("Upload image"); tsbUploadImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbUploadImage.Image = Resources.drive_globe; tsbUploadImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateUploadImage); tsMain.Items.Add(tsbUploadImage); ToolStripButton tsbPrintImage = new ToolStripButton("Print image..."); tsbPrintImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbPrintImage.Image = Resources.printer; tsbPrintImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotatePrintImage); tsMain.Items.Add(tsbPrintImage); tsMain.Items.Add(new ToolStripSeparator()); } #endregion Editor mode #region Tools foreach (ShapeType shapeType in Helpers.GetEnums <ShapeType>()) { if (form.Mode == RegionCaptureMode.Editor) { if (IsShapeTypeRegion(shapeType)) { continue; } } else if (shapeType == ShapeType.DrawingRectangle) { tsMain.Items.Add(new ToolStripSeparator()); } ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription()); tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image; Image img = null; switch (shapeType) { case ShapeType.RegionRectangle: img = Resources.layer_shape_region; break; case ShapeType.RegionRoundedRectangle: img = Resources.layer_shape_round_region; break; case ShapeType.RegionEllipse: img = Resources.layer_shape_ellipse_region; break; case ShapeType.RegionFreehand: img = Resources.layer_shape_polygon; break; case ShapeType.DrawingRectangle: img = Resources.layer_shape; break; case ShapeType.DrawingRoundedRectangle: img = Resources.layer_shape_round; break; case ShapeType.DrawingEllipse: img = Resources.layer_shape_ellipse; break; case ShapeType.DrawingFreehand: img = Resources.layer_shape_curve; break; case ShapeType.DrawingLine: img = Resources.layer_shape_line; break; case ShapeType.DrawingArrow: img = Resources.layer_shape_arrow; break; case ShapeType.DrawingText: img = Resources.layer_shape_text; break; case ShapeType.DrawingSpeechBalloon: img = Resources.balloon_box_left; break; case ShapeType.DrawingStep: img = Resources.counter_reset; break; case ShapeType.DrawingImage: img = Resources.image; break; case ShapeType.EffectBlur: img = Resources.layer_shade; break; case ShapeType.EffectPixelate: img = Resources.grid; break; case ShapeType.EffectHighlight: img = Resources.highlighter_text; break; } tsbShapeType.Image = img; tsbShapeType.Checked = shapeType == CurrentShapeType; tsbShapeType.Tag = shapeType; tsbShapeType.MouseDown += (sender, e) => { tsbShapeType.RadioCheck(); CurrentShapeType = shapeType; }; tsMain.Items.Add(tsbShapeType); } #endregion Tools #region Selected object tsMain.Items.Add(new ToolStripSeparator()); tsbBorderColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Border_color___); tsbBorderColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbBorderColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color borderColor; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { borderColor = AnnotationOptions.TextBorderColor; } else if (shapeType == ShapeType.DrawingStep) { borderColor = AnnotationOptions.StepBorderColor; } else { borderColor = AnnotationOptions.BorderColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderColor = dialogColor.NewColor; } else { AnnotationOptions.BorderColor = dialogColor.NewColor; } UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsMain.Items.Add(tsbBorderColor); tsbFillColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Fill_color___); tsbFillColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbFillColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color fillColor; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { fillColor = AnnotationOptions.TextFillColor; } else if (shapeType == ShapeType.DrawingStep) { fillColor = AnnotationOptions.StepFillColor; } else { fillColor = AnnotationOptions.FillColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextFillColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepFillColor = dialogColor.NewColor; } else { AnnotationOptions.FillColor = dialogColor.NewColor; } UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsMain.Items.Add(tsbFillColor); tsbHighlightColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Highlight_color___); tsbHighlightColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbHighlightColor.Click += (sender, e) => { PauseForm(); using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { AnnotationOptions.HighlightColor = dialogColor.NewColor; UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsMain.Items.Add(tsbHighlightColor); tsddbShapeOptions = new ToolStripDropDownButton("Shape options"); tsddbShapeOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbShapeOptions.HideImageMargin(); tsddbShapeOptions.Image = Resources.layer__pencil; tsMain.Items.Add(tsddbShapeOptions); tslnudBorderSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Border_size_); tslnudBorderSize.Content.Minimum = 0; tslnudBorderSize.Content.Maximum = 20; tslnudBorderSize.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; int borderSize = (int)tslnudBorderSize.Content.Value; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderSize = borderSize; } else { AnnotationOptions.BorderSize = borderSize; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBorderSize); tslnudCornerRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_); tslnudCornerRadius.Content.Minimum = 0; tslnudCornerRadius.Content.Maximum = 150; tslnudCornerRadius.Content.Increment = 3; tslnudCornerRadius.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; if (shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle) { AnnotationOptions.RoundedRectangleRadius = (int)tslnudCornerRadius.Content.Value; } else if (shapeType == ShapeType.DrawingText) { AnnotationOptions.TextCornerRadius = (int)tslnudCornerRadius.Content.Value; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudCornerRadius); tslnudBlurRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Blur_radius_); tslnudBlurRadius.Content.Minimum = 2; tslnudBlurRadius.Content.Maximum = 100; tslnudBlurRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBlurRadius); tslnudPixelateSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Pixel_size_); tslnudPixelateSize.Content.Minimum = 2; tslnudPixelateSize.Content.Maximum = 100; tslnudPixelateSize.Content.ValueChanged = (sender, e) => { AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudPixelateSize); // In dropdown menu if only last item is visible then menu opens at 0, 0 position on first open, so need to add dummy item to solve this weird bug... tsddbShapeOptions.DropDownItems.Add(new ToolStripSeparator() { Visible = false }); tsbUndoObject = new ToolStripButton("Undo object"); tsbUndoObject.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbUndoObject.Image = Resources.arrow_circle_225_left; tsbUndoObject.MouseDown += (sender, e) => UndoShape(); tsMain.Items.Add(tsbUndoObject); tsbDeleteAll = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Delete_all_objects); tsbDeleteAll.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbDeleteAll.Image = Resources.eraser; tsbDeleteAll.MouseDown += (sender, e) => DeleteAllShapes(); tsMain.Items.Add(tsbDeleteAll); #endregion Selected object #region Capture if (form.Mode != RegionCaptureMode.Editor) { tsMain.Items.Add(new ToolStripSeparator()); ToolStripDropDownButton tsddbCapture = new ToolStripDropDownButton("Capture"); tsddbCapture.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbCapture.Image = Resources.camera; tsMain.Items.Add(tsddbCapture); tsmiRegionCapture = new ToolStripMenuItem("Capture regions"); tsmiRegionCapture.Image = Resources.layers; tsmiRegionCapture.MouseDown += (sender, e) => { form.UpdateRegionPath(); form.Close(RegionResult.Region); }; tsddbCapture.DropDownItems.Add(tsmiRegionCapture); ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_fullscreen); tsmiFullscreenCapture.Image = Resources.layer_fullscreen; tsmiFullscreenCapture.MouseDown += (sender, e) => form.Close(RegionResult.Fullscreen); tsddbCapture.DropDownItems.Add(tsmiFullscreenCapture); ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_active_monitor); tsmiActiveMonitorCapture.Image = Resources.monitor; tsmiActiveMonitorCapture.MouseDown += (sender, e) => form.Close(RegionResult.ActiveMonitor); tsddbCapture.DropDownItems.Add(tsmiActiveMonitorCapture); ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_monitor); tsmiMonitorCapture.HideImageMargin(); tsmiMonitorCapture.Image = Resources.monitor_window; tsddbCapture.DropDownItems.Add(tsmiMonitorCapture); Screen[] screens = Screen.AllScreens; for (int i = 0; i < screens.Length; i++) { Screen screen = screens[i]; ToolStripMenuItem tsmi = new ToolStripMenuItem(string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height)); int index = i; tsmi.MouseDown += (sender, e) => { form.MonitorIndex = index; form.Close(RegionResult.Monitor); }; tsmiMonitorCapture.DropDownItems.Add(tsmi); } } #endregion Capture #region Options if (form.Mode != RegionCaptureMode.Editor) { tsMain.Items.Add(new ToolStripSeparator()); ToolStripDropDownButton tsddbOptions = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Options); tsddbOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbOptions.Image = Resources.gear; tsMain.Items.Add(tsddbOptions); tsmiQuickCrop = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Multi_region_mode); tsmiQuickCrop.Checked = !Config.QuickCrop; tsmiQuickCrop.CheckOnClick = true; tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked; tsddbOptions.DropDownItems.Add(tsmiQuickCrop); ToolStripMenuItem tsmiTips = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_tips); tsmiTips.Checked = Config.ShowHotkeys; tsmiTips.CheckOnClick = true; tsmiTips.Click += (sender, e) => Config.ShowHotkeys = tsmiTips.Checked; tsddbOptions.DropDownItems.Add(tsmiTips); ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_position_and_size_info); tsmiShowInfo.Checked = Config.ShowInfo; tsmiShowInfo.CheckOnClick = true; tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked; tsddbOptions.DropDownItems.Add(tsmiShowInfo); ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_magnifier); tsmiShowMagnifier.Checked = Config.ShowMagnifier; tsmiShowMagnifier.CheckOnClick = true; tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiShowMagnifier); ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Square_shape_magnifier); tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier; tsmiUseSquareMagnifier.CheckOnClick = true; tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiUseSquareMagnifier); ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_count_); tslnudMagnifierPixelCount.Content.Minimum = RegionCaptureOptions.MagnifierPixelCountMinimum; tslnudMagnifierPixelCount.Content.Maximum = RegionCaptureOptions.MagnifierPixelCountMaximum; tslnudMagnifierPixelCount.Content.Increment = 2; tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount; tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelCount); ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_size_); tslnudMagnifierPixelSize.Content.Minimum = RegionCaptureOptions.MagnifierPixelSizeMinimum; tslnudMagnifierPixelSize.Content.Maximum = RegionCaptureOptions.MagnifierPixelSizeMaximum; tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize; tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelSize); ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_screen_wide_crosshair); tsmiShowCrosshair.Checked = Config.ShowCrosshair; tsmiShowCrosshair.CheckOnClick = true; tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked; tsddbOptions.DropDownItems.Add(tsmiShowCrosshair); ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Fixed_size_region_mode); tsmiFixedSize.Checked = Config.IsFixedSize; tsmiFixedSize.CheckOnClick = true; tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked; tsddbOptions.DropDownItems.Add(tsmiFixedSize); ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Width_, Resources.ShapeManager_CreateContextMenu_Height_); tslnudFixedSize.Content.Minimum = 10; tslnudFixedSize.Content.Maximum = 10000; tslnudFixedSize.Content.Increment = 10; tslnudFixedSize.Content.Value = Config.FixedSize.Width; tslnudFixedSize.Content.Value2 = Config.FixedSize.Height; tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2); tsddbOptions.DropDownItems.Add(tslnudFixedSize); ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_FPS); tsmiShowFPS.Checked = Config.ShowFPS; tsmiShowFPS.CheckOnClick = true; tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked; tsddbOptions.DropDownItems.Add(tsmiShowFPS); ToolStripMenuItem tsmiRememberMenuState = new ToolStripMenuItem("Remember menu state"); tsmiRememberMenuState.Checked = Config.RememberMenuState; tsmiRememberMenuState.CheckOnClick = true; tsmiRememberMenuState.Click += (sender, e) => Config.RememberMenuState = tsmiRememberMenuState.Checked; tsddbOptions.DropDownItems.Add(tsmiRememberMenuState); } #endregion Options ToolStripLabel tslDragRight = new ToolStripLabel() { Alignment = ToolStripItemAlignment.Right, DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(0, 0, 2, 0), Padding = new Padding(2) }; tsMain.Items.Add(tslDragRight); tslDragLeft.MouseDown += TslDrag_MouseDown; tslDragRight.MouseDown += TslDrag_MouseDown; tslDragLeft.MouseEnter += TslDrag_MouseEnter; tslDragRight.MouseEnter += TslDrag_MouseEnter; tslDragLeft.MouseLeave += TslDrag_MouseLeave; tslDragRight.MouseLeave += TslDrag_MouseLeave; tsMain.ResumeLayout(false); tsMain.PerformLayout(); menuForm.ResumeLayout(false); menuForm.Show(form); foreach (ToolStripItem tsi in tsMain.Items.OfType <ToolStripItem>()) { if (!string.IsNullOrEmpty(tsi.Text)) { tsi.MouseEnter += (sender, e) => { Point pos = CaptureHelpers.ScreenToClient(menuForm.PointToScreen(tsi.Bounds.Location)); pos.Y += tsi.Height + 8; MenuTextAnimation.Position = pos; MenuTextAnimation.Start(tsi.Text); }; tsi.MouseLeave += TsMain_MouseLeave; } } UpdateMenu(); CurrentShapeTypeChanged += shapeType => UpdateMenu(); CurrentShapeChanged += shape => UpdateMenu(); ConfigureMenuState(); form.Activate(); }
private void CreateToolbar() { menuForm = new Form() { AutoScaleDimensions = new SizeF(6F, 13F), AutoScaleMode = AutoScaleMode.Font, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ClientSize = new Size(759, 509), FormBorderStyle = FormBorderStyle.None, Location = new Point(200, 200), ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, Text = "ShareX - Region capture menu", TopMost = true }; menuForm.KeyUp += MenuForm_KeyUp; menuForm.LocationChanged += MenuForm_LocationChanged; menuForm.SuspendLayout(); tsMain = new ToolStripEx() { AutoSize = true, CanOverflow = false, ClickThrough = true, Dock = DockStyle.None, GripStyle = ToolStripGripStyle.Hidden, Location = new Point(0, 0), MinimumSize = new Size(10, 30), Padding = new Padding(0, 0, 0, 0), Renderer = new CustomToolStripProfessionalRenderer(), TabIndex = 0, ShowItemToolTips = false }; tsMain.MouseLeave += TsMain_MouseLeave; tsMain.SuspendLayout(); // https://www.medo64.com/2014/01/scaling-toolstrip-with-dpi/ using (Graphics g = menuForm.CreateGraphics()) { double scale = Math.Max(g.DpiX, g.DpiY) / 96.0; double newScale = ((int)Math.Floor(scale * 100) / 25 * 25) / 100.0; if (newScale > 1) { int newWidth = (int)(tsMain.ImageScalingSize.Width * newScale); int newHeight = (int)(tsMain.ImageScalingSize.Height * newScale); tsMain.ImageScalingSize = new Size(newWidth, newHeight); } } menuForm.Controls.Add(tsMain); tslDragLeft = new ToolStripLabel() { DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(2, 0, 2, 0), Padding = new Padding(2) }; tsMain.Items.Add(tslDragLeft); if (form.Mode == RegionCaptureMode.Editor) { #region Editor mode ToolStripButton tsbCompleteEdit = new ToolStripButton("Run after capture tasks"); tsbCompleteEdit.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCompleteEdit.Image = Resources.tick; tsbCompleteEdit.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateRunAfterCaptureTasks); tsMain.Items.Add(tsbCompleteEdit); ToolStripButton tsbSaveImage = new ToolStripButton("Save image"); tsbSaveImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImage.Enabled = !string.IsNullOrEmpty(form.ImageFilePath); tsbSaveImage.Image = Resources.disk_black; tsbSaveImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImage); tsMain.Items.Add(tsbSaveImage); ToolStripButton tsbSaveImageAs = new ToolStripButton("Save image as..."); tsbSaveImageAs.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImageAs.Image = Resources.disks_black; tsbSaveImageAs.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImageAs); tsMain.Items.Add(tsbSaveImageAs); ToolStripButton tsbCopyImage = new ToolStripButton("Copy image to clipboard"); tsbCopyImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCopyImage.Image = Resources.clipboard; tsbCopyImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateCopyImage); tsMain.Items.Add(tsbCopyImage); ToolStripButton tsbUploadImage = new ToolStripButton("Upload image"); tsbUploadImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbUploadImage.Image = Resources.drive_globe; tsbUploadImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateUploadImage); tsMain.Items.Add(tsbUploadImage); ToolStripButton tsbPrintImage = new ToolStripButton("Print image..."); tsbPrintImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbPrintImage.Image = Resources.printer; tsbPrintImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotatePrintImage); tsMain.Items.Add(tsbPrintImage); tsMain.Items.Add(new ToolStripSeparator()); #endregion Editor mode } #region Tools foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>()) { if (form.Mode == RegionCaptureMode.Editor) { if (IsShapeTypeRegion(shapeType)) { continue; } } else if (shapeType == ShapeType.DrawingRectangle) { tsMain.Items.Add(new ToolStripSeparator()); } ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription()); tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image; Image img = null; switch (shapeType) { case ShapeType.RegionRectangle: img = Resources.layer_shape_region; break; case ShapeType.RegionEllipse: img = Resources.layer_shape_ellipse_region; break; case ShapeType.RegionFreehand: img = Resources.layer_shape_polygon; break; case ShapeType.DrawingRectangle: img = Resources.layer_shape; break; case ShapeType.DrawingEllipse: img = Resources.layer_shape_ellipse; break; case ShapeType.DrawingFreehand: img = Resources.layer_shape_curve; break; case ShapeType.DrawingLine: img = Resources.layer_shape_line; break; case ShapeType.DrawingArrow: img = Resources.layer_shape_arrow; break; case ShapeType.DrawingText: img = Resources.layer_shape_text; break; case ShapeType.DrawingSpeechBalloon: img = Resources.balloon_box_left; break; case ShapeType.DrawingStep: img = Resources.counter_reset; break; case ShapeType.DrawingImage: img = Resources.image; break; case ShapeType.EffectBlur: img = Resources.layer_shade; break; case ShapeType.EffectPixelate: img = Resources.grid; break; case ShapeType.EffectHighlight: img = Resources.highlighter_text; break; } tsbShapeType.Image = img; tsbShapeType.Checked = shapeType == CurrentShapeType; tsbShapeType.Tag = shapeType; tsbShapeType.MouseDown += (sender, e) => { tsbShapeType.RadioCheck(); CurrentShapeType = shapeType; }; tsMain.Items.Add(tsbShapeType); } #endregion Tools #region Shape options tsMain.Items.Add(new ToolStripSeparator()); tsbBorderColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Border_color___); tsbBorderColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbBorderColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color borderColor; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { borderColor = AnnotationOptions.TextBorderColor; } else if (shapeType == ShapeType.DrawingStep) { borderColor = AnnotationOptions.StepBorderColor; } else { borderColor = AnnotationOptions.BorderColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderColor = dialogColor.NewColor; } else { AnnotationOptions.BorderColor = dialogColor.NewColor; } UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsMain.Items.Add(tsbBorderColor); tsbFillColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Fill_color___); tsbFillColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbFillColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color fillColor; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { fillColor = AnnotationOptions.TextFillColor; } else if (shapeType == ShapeType.DrawingStep) { fillColor = AnnotationOptions.StepFillColor; } else { fillColor = AnnotationOptions.FillColor; } using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextFillColor = dialogColor.NewColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepFillColor = dialogColor.NewColor; } else { AnnotationOptions.FillColor = dialogColor.NewColor; } UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsMain.Items.Add(tsbFillColor); tsbHighlightColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Highlight_color___); tsbHighlightColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbHighlightColor.Click += (sender, e) => { PauseForm(); using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor)) { if (dialogColor.ShowDialog() == DialogResult.OK) { AnnotationOptions.HighlightColor = dialogColor.NewColor; UpdateMenu(); UpdateCurrentShape(); } } ResumeForm(); }; tsMain.Items.Add(tsbHighlightColor); tsddbShapeOptions = new ToolStripDropDownButton("Shape options"); tsddbShapeOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbShapeOptions.Image = Resources.layer__pencil; tsMain.Items.Add(tsddbShapeOptions); tslnudBorderSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Border_size_); tslnudBorderSize.Content.Minimum = 0; tslnudBorderSize.Content.Maximum = 20; tslnudBorderSize.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; int borderSize = (int)tslnudBorderSize.Content.Value; if (shapeType == ShapeType.DrawingText || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderSize = borderSize; } else { AnnotationOptions.BorderSize = borderSize; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBorderSize); tslnudCornerRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_); tslnudCornerRadius.Content.Minimum = 0; tslnudCornerRadius.Content.Maximum = 150; tslnudCornerRadius.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; if (shapeType == ShapeType.RegionRectangle) { AnnotationOptions.RegionCornerRadius = (int)tslnudCornerRadius.Content.Value; } else if (shapeType == ShapeType.DrawingRectangle || shapeType == ShapeType.DrawingText) { AnnotationOptions.DrawingCornerRadius = (int)tslnudCornerRadius.Content.Value; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudCornerRadius); tslnudBlurRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Blur_radius_); tslnudBlurRadius.Content.Minimum = 3; tslnudBlurRadius.Content.Maximum = 199; tslnudBlurRadius.Content.Increment = 2; tslnudBlurRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBlurRadius); tslnudPixelateSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Pixel_size_); tslnudPixelateSize.Content.Minimum = 2; tslnudPixelateSize.Content.Maximum = 10000; tslnudPixelateSize.Content.ValueChanged = (sender, e) => { AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudPixelateSize); tsmiShadow = new ToolStripMenuItem("Drop shadow"); tsmiShadow.Checked = true; tsmiShadow.CheckOnClick = true; tsmiShadow.Click += (sender, e) => { AnnotationOptions.Shadow = tsmiShadow.Checked; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tsmiShadow); // In dropdown menu if only last item is visible then menu opens at 0, 0 position on first open, so need to add dummy item to solve this weird bug... tsddbShapeOptions.DropDownItems.Add(new ToolStripSeparator() { Visible = false }); #endregion Shape options #region Edit ToolStripDropDownButton tsddbEdit = new ToolStripDropDownButton("Edit"); tsddbEdit.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbEdit.Image = Resources.wrench_screwdriver; tsMain.Items.Add(tsddbEdit); tsmiUndo = new ToolStripMenuItem("Undo"); tsmiUndo.Image = Resources.arrow_circle_225_left; tsmiUndo.ShortcutKeyDisplayString = "Ctrl+Z"; tsmiUndo.MouseDown += (sender, e) => UndoShape(); tsddbEdit.DropDownItems.Add(tsmiUndo); tsddbEdit.DropDownItems.Add(new ToolStripSeparator()); tsmiDelete = new ToolStripMenuItem("Delete"); tsmiDelete.Image = Resources.layer__minus; tsmiDelete.ShortcutKeyDisplayString = "Del"; tsmiDelete.MouseDown += (sender, e) => DeleteCurrentShape(); tsddbEdit.DropDownItems.Add(tsmiDelete); tsmiDeleteAll = new ToolStripMenuItem("Delete all"); tsmiDeleteAll.Image = Resources.eraser; tsmiDeleteAll.ShortcutKeyDisplayString = "Shift+Del"; tsmiDeleteAll.MouseDown += (sender, e) => DeleteAllShapes(); tsddbEdit.DropDownItems.Add(tsmiDeleteAll); tsddbEdit.DropDownItems.Add(new ToolStripSeparator()); tsmiMoveTop = new ToolStripMenuItem("Bring to front"); tsmiMoveTop.Image = Resources.layers_stack_arrange; tsmiMoveTop.ShortcutKeyDisplayString = "Home"; tsmiMoveTop.MouseDown += (sender, e) => MoveCurrentShapeTop(); tsddbEdit.DropDownItems.Add(tsmiMoveTop); tsmiMoveUp = new ToolStripMenuItem("Bring forward"); tsmiMoveUp.Image = Resources.layers_arrange; tsmiMoveUp.ShortcutKeyDisplayString = "Page up"; tsmiMoveUp.MouseDown += (sender, e) => MoveCurrentShapeUp(); tsddbEdit.DropDownItems.Add(tsmiMoveUp); tsmiMoveDown = new ToolStripMenuItem("Send backward"); tsmiMoveDown.Image = Resources.layers_arrange_back; tsmiMoveDown.ShortcutKeyDisplayString = "Page down"; tsmiMoveDown.MouseDown += (sender, e) => MoveCurrentShapeDown(); tsddbEdit.DropDownItems.Add(tsmiMoveDown); tsmiMoveBottom = new ToolStripMenuItem("Send to back"); tsmiMoveBottom.Image = Resources.layers_stack_arrange_back; tsmiMoveBottom.ShortcutKeyDisplayString = "End"; tsmiMoveBottom.MouseDown += (sender, e) => MoveCurrentShapeBottom(); tsddbEdit.DropDownItems.Add(tsmiMoveBottom); #endregion Edit if (form.Mode != RegionCaptureMode.Editor) { tsMain.Items.Add(new ToolStripSeparator()); #region Capture ToolStripDropDownButton tsddbCapture = new ToolStripDropDownButton("Capture"); tsddbCapture.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbCapture.Image = Resources.camera; tsMain.Items.Add(tsddbCapture); tsmiRegionCapture = new ToolStripMenuItem("Capture regions"); tsmiRegionCapture.Image = Resources.layer; tsmiRegionCapture.ShortcutKeyDisplayString = "Enter"; tsmiRegionCapture.MouseDown += (sender, e) => { form.UpdateRegionPath(); form.Close(RegionResult.Region); }; tsddbCapture.DropDownItems.Add(tsmiRegionCapture); if (RegionCaptureForm.LastRegionFillPath != null) { ToolStripMenuItem tsmiLastRegionCapture = new ToolStripMenuItem("Capture last region"); tsmiLastRegionCapture.Image = Resources.layers; tsmiLastRegionCapture.MouseDown += (sender, e) => form.Close(RegionResult.LastRegion); tsddbCapture.DropDownItems.Add(tsmiLastRegionCapture); } ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_fullscreen); tsmiFullscreenCapture.Image = Resources.layer_fullscreen; tsmiFullscreenCapture.ShortcutKeyDisplayString = "Space"; tsmiFullscreenCapture.MouseDown += (sender, e) => form.Close(RegionResult.Fullscreen); tsddbCapture.DropDownItems.Add(tsmiFullscreenCapture); ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_active_monitor); tsmiActiveMonitorCapture.Image = Resources.monitor; tsmiActiveMonitorCapture.ShortcutKeyDisplayString = "~"; tsmiActiveMonitorCapture.MouseDown += (sender, e) => form.Close(RegionResult.ActiveMonitor); tsddbCapture.DropDownItems.Add(tsmiActiveMonitorCapture); ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_monitor); tsmiMonitorCapture.HideImageMargin(); tsmiMonitorCapture.Image = Resources.monitor_window; tsddbCapture.DropDownItems.Add(tsmiMonitorCapture); Screen[] screens = Screen.AllScreens; for (int i = 0; i < screens.Length; i++) { Screen screen = screens[i]; ToolStripMenuItem tsmi = new ToolStripMenuItem($"{screen.Bounds.Width}x{screen.Bounds.Height}"); tsmi.ShortcutKeyDisplayString = (i + 1).ToString(); int index = i; tsmi.MouseDown += (sender, e) => { form.MonitorIndex = index; form.Close(RegionResult.Monitor); }; tsmiMonitorCapture.DropDownItems.Add(tsmi); } #endregion Capture #region Options ToolStripDropDownButton tsddbOptions = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Options); tsddbOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbOptions.Image = Resources.gear; tsMain.Items.Add(tsddbOptions); tsmiQuickCrop = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Multi_region_mode); tsmiQuickCrop.Checked = !Config.QuickCrop; tsmiQuickCrop.CheckOnClick = true; tsmiQuickCrop.ShortcutKeyDisplayString = "Q"; tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked; tsddbOptions.DropDownItems.Add(tsmiQuickCrop); tsmiTips = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_tips); tsmiTips.Checked = Config.ShowHotkeys; tsmiTips.CheckOnClick = true; tsmiTips.ShortcutKeyDisplayString = "F1"; tsmiTips.Click += (sender, e) => Config.ShowHotkeys = tsmiTips.Checked; tsddbOptions.DropDownItems.Add(tsmiTips); ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_position_and_size_info); tsmiShowInfo.Checked = Config.ShowInfo; tsmiShowInfo.CheckOnClick = true; tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked; tsddbOptions.DropDownItems.Add(tsmiShowInfo); ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_magnifier); tsmiShowMagnifier.Checked = Config.ShowMagnifier; tsmiShowMagnifier.CheckOnClick = true; tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiShowMagnifier); ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Square_shape_magnifier); tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier; tsmiUseSquareMagnifier.CheckOnClick = true; tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiUseSquareMagnifier); ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_count_); tslnudMagnifierPixelCount.Content.Minimum = RegionCaptureOptions.MagnifierPixelCountMinimum; tslnudMagnifierPixelCount.Content.Maximum = RegionCaptureOptions.MagnifierPixelCountMaximum; tslnudMagnifierPixelCount.Content.Increment = 2; tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount; tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelCount); ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_size_); tslnudMagnifierPixelSize.Content.Minimum = RegionCaptureOptions.MagnifierPixelSizeMinimum; tslnudMagnifierPixelSize.Content.Maximum = RegionCaptureOptions.MagnifierPixelSizeMaximum; tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize; tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelSize); ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_screen_wide_crosshair); tsmiShowCrosshair.Checked = Config.ShowCrosshair; tsmiShowCrosshair.CheckOnClick = true; tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked; tsddbOptions.DropDownItems.Add(tsmiShowCrosshair); ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Fixed_size_region_mode); tsmiFixedSize.Checked = Config.IsFixedSize; tsmiFixedSize.CheckOnClick = true; tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked; tsddbOptions.DropDownItems.Add(tsmiFixedSize); ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Width_, Resources.ShapeManager_CreateContextMenu_Height_); tslnudFixedSize.Content.Minimum = 10; tslnudFixedSize.Content.Maximum = 10000; tslnudFixedSize.Content.Increment = 10; tslnudFixedSize.Content.Value = Config.FixedSize.Width; tslnudFixedSize.Content.Value2 = Config.FixedSize.Height; tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2); tsddbOptions.DropDownItems.Add(tslnudFixedSize); ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_FPS); tsmiShowFPS.Checked = Config.ShowFPS; tsmiShowFPS.CheckOnClick = true; tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked; tsddbOptions.DropDownItems.Add(tsmiShowFPS); ToolStripMenuItem tsmiRememberMenuState = new ToolStripMenuItem("Remember menu state"); tsmiRememberMenuState.Checked = Config.RememberMenuState; tsmiRememberMenuState.CheckOnClick = true; tsmiRememberMenuState.Click += (sender, e) => Config.RememberMenuState = tsmiRememberMenuState.Checked; tsddbOptions.DropDownItems.Add(tsmiRememberMenuState); #endregion Options } ToolStripLabel tslDragRight = new ToolStripLabel() { Alignment = ToolStripItemAlignment.Right, DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(0, 0, 2, 0), Padding = new Padding(2) }; tsMain.Items.Add(tslDragRight); tslDragLeft.MouseDown += TslDrag_MouseDown; tslDragRight.MouseDown += TslDrag_MouseDown; tslDragLeft.MouseEnter += TslDrag_MouseEnter; tslDragRight.MouseEnter += TslDrag_MouseEnter; tslDragLeft.MouseLeave += TslDrag_MouseLeave; tslDragRight.MouseLeave += TslDrag_MouseLeave; tsMain.ResumeLayout(false); tsMain.PerformLayout(); menuForm.ResumeLayout(false); menuForm.Show(form); foreach (ToolStripItem tsi in tsMain.Items.OfType<ToolStripItem>()) { if (!string.IsNullOrEmpty(tsi.Text)) { tsi.MouseEnter += (sender, e) => { Point pos = CaptureHelpers.ScreenToClient(menuForm.PointToScreen(tsi.Bounds.Location)); pos.Y += tsi.Height + 8; MenuTextAnimation.Position = pos; MenuTextAnimation.Start(tsi.Text); }; tsi.MouseLeave += TsMain_MouseLeave; } } UpdateMenu(); CurrentShapeChanged += shape => UpdateMenu(); CurrentShapeTypeChanged += shapeType => UpdateMenu(); ShapeCreated += shape => UpdateMenu(); ConfigureMenuState(); form.Activate(); }
private void CreateToolbar() { menuForm = new Form() { AutoScaleDimensions = new SizeF(6F, 13F), AutoScaleMode = AutoScaleMode.Font, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ClientSize = new Size(759, 509), FormBorderStyle = FormBorderStyle.None, Location = new Point(200, 200), ShowInTaskbar = false, StartPosition = FormStartPosition.Manual, Text = "ShareX - Region capture menu", TopMost = true }; menuForm.Shown += MenuForm_Shown; menuForm.KeyDown += MenuForm_KeyDown; menuForm.KeyUp += MenuForm_KeyUp; menuForm.LocationChanged += MenuForm_LocationChanged; menuForm.SuspendLayout(); tsMain = new ToolStripEx() { AutoSize = true, CanOverflow = false, ClickThrough = true, Dock = DockStyle.None, GripStyle = ToolStripGripStyle.Hidden, Location = new Point(0, 0), MinimumSize = new Size(10, 30), Padding = new Padding(0, 1, 0, 0), Renderer = new CustomToolStripProfessionalRenderer(), TabIndex = 0, ShowItemToolTips = false }; tsMain.MouseLeave += TsMain_MouseLeave; tsMain.SuspendLayout(); // https://www.medo64.com/2014/01/scaling-toolstrip-with-dpi/ using (Graphics g = menuForm.CreateGraphics()) { double scale = Math.Max(g.DpiX, g.DpiY) / 96.0; double newScale = ((int)Math.Floor(scale * 100) / 25 * 25) / 100.0; if (newScale > 1) { int newWidth = (int)(tsMain.ImageScalingSize.Width * newScale); int newHeight = (int)(tsMain.ImageScalingSize.Height * newScale); tsMain.ImageScalingSize = new Size(newWidth, newHeight); } } menuForm.Controls.Add(tsMain); tslDragLeft = new ToolStripLabel() { DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(2, 0, 2, 0), Padding = new Padding(2) }; tsMain.Items.Add(tslDragLeft); if (form.IsEditorMode) { #region Editor mode ToolStripButton tsbCompleteEdit = new ToolStripButton(); if (form.Mode == RegionCaptureMode.Editor) { tsbCompleteEdit.Text = Resources.ShapeManager_CreateToolbar_RunAfterCaptureTasks; } else { tsbCompleteEdit.Text = Resources.ShapeManager_CreateToolbar_ApplyChangesContinueTaskEnter; } tsbCompleteEdit.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCompleteEdit.Image = Resources.tick; tsbCompleteEdit.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateRunAfterCaptureTasks); tsMain.Items.Add(tsbCompleteEdit); if (form.Mode == RegionCaptureMode.TaskEditor) { ToolStripButton tsbClose = new ToolStripButton(Resources.ShapeManager_CreateToolbar_ContinueTaskSpaceOrRightClick); tsbClose.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbClose.Image = Resources.control; tsbClose.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateContinueTask); tsMain.Items.Add(tsbClose); ToolStripButton tsbCloseCancel = new ToolStripButton(Resources.ShapeManager_CreateToolbar_CancelTaskEsc); tsbCloseCancel.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCloseCancel.Image = Resources.cross; tsbCloseCancel.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateCancelTask); tsMain.Items.Add(tsbCloseCancel); } if (form.Mode == RegionCaptureMode.TaskEditor) { tsMain.Items.Add(new ToolStripSeparator()); } ToolStripButton tsbSaveImage = new ToolStripButton(Resources.ShapeManager_CreateToolbar_SaveImage); tsbSaveImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImage.Enabled = File.Exists(form.ImageFilePath); tsbSaveImage.Image = Resources.disk_black; tsbSaveImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImage); tsMain.Items.Add(tsbSaveImage); ToolStripButton tsbSaveImageAs = new ToolStripButton(Resources.ShapeManager_CreateToolbar_SaveImageAs); tsbSaveImageAs.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbSaveImageAs.Image = Resources.disks_black; tsbSaveImageAs.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateSaveImageAs); tsMain.Items.Add(tsbSaveImageAs); ToolStripButton tsbCopyImage = new ToolStripButton(Resources.ShapeManager_CreateToolbar_CopyImageToClipboard); tsbCopyImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbCopyImage.Image = Resources.clipboard; tsbCopyImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateCopyImage); tsMain.Items.Add(tsbCopyImage); ToolStripButton tsbUploadImage = new ToolStripButton(Resources.ShapeManager_CreateToolbar_UploadImage); tsbUploadImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbUploadImage.Image = Resources.drive_globe; tsbUploadImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotateUploadImage); tsMain.Items.Add(tsbUploadImage); ToolStripButton tsbPrintImage = new ToolStripButton(Resources.ShapeManager_CreateToolbar_PrintImage); tsbPrintImage.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbPrintImage.Image = Resources.printer; tsbPrintImage.MouseDown += (sender, e) => form.Close(RegionResult.AnnotatePrintImage); tsMain.Items.Add(tsbPrintImage); tsMain.Items.Add(new ToolStripSeparator()); #endregion Editor mode } #region Tools foreach (ShapeType shapeType in Helpers.GetEnums <ShapeType>()) { if (form.IsEditorMode) { if (IsShapeTypeRegion(shapeType)) { continue; } } else if (shapeType == ShapeType.DrawingRectangle) { tsMain.Items.Add(new ToolStripSeparator()); } else if (shapeType == ShapeType.DrawingCrop) { continue; } ToolStripButton tsbShapeType = new ToolStripButton(shapeType.GetLocalizedDescription()); tsbShapeType.DisplayStyle = ToolStripItemDisplayStyle.Image; Image img = null; switch (shapeType) { case ShapeType.RegionRectangle: img = Resources.layer_shape_region; break; case ShapeType.RegionEllipse: img = Resources.layer_shape_ellipse_region; break; case ShapeType.RegionFreehand: img = Resources.layer_shape_polygon; break; case ShapeType.DrawingRectangle: img = Resources.layer_shape; break; case ShapeType.DrawingEllipse: img = Resources.layer_shape_ellipse; break; case ShapeType.DrawingFreehand: img = Resources.pencil; break; case ShapeType.DrawingLine: img = Resources.layer_shape_line; break; case ShapeType.DrawingArrow: img = Resources.layer_shape_arrow; break; case ShapeType.DrawingTextOutline: img = Resources.edit_outline; break; case ShapeType.DrawingTextBackground: img = Resources.edit_shade; break; case ShapeType.DrawingSpeechBalloon: img = Resources.balloon_box_left; break; case ShapeType.DrawingStep: img = Resources.counter_reset; break; case ShapeType.DrawingImage: img = Resources.folder_open_image; break; case ShapeType.DrawingImageScreen: img = Resources.monitor_image; break; case ShapeType.DrawingCursor: img = Resources.cursor; break; case ShapeType.EffectBlur: img = Resources.layer_shade; break; case ShapeType.EffectPixelate: img = Resources.grid; break; case ShapeType.EffectHighlight: img = Resources.highlighter_text; break; case ShapeType.DrawingCrop: img = Resources.image_crop; break; } tsbShapeType.Image = img; tsbShapeType.Checked = shapeType == CurrentShapeType; tsbShapeType.Tag = shapeType; tsbShapeType.MouseDown += (sender, e) => { tsbShapeType.RadioCheck(); CurrentShapeType = shapeType; }; tsMain.Items.Add(tsbShapeType); } #endregion Tools #region Shape options tsMain.Items.Add(new ToolStripSeparator()); tsbBorderColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Border_color___); tsbBorderColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbBorderColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color borderColor; if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon) { borderColor = AnnotationOptions.TextBorderColor; } else if (shapeType == ShapeType.DrawingTextOutline) { borderColor = AnnotationOptions.TextOutlineBorderColor; } else if (shapeType == ShapeType.DrawingStep) { borderColor = AnnotationOptions.StepBorderColor; } else { borderColor = AnnotationOptions.BorderColor; } if (ColorPickerForm.PickColor(borderColor, out Color newColor)) { if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderColor = newColor; } else if (shapeType == ShapeType.DrawingTextOutline) { AnnotationOptions.TextOutlineBorderColor = newColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderColor = newColor; } else { AnnotationOptions.BorderColor = newColor; } UpdateMenu(); UpdateCurrentShape(); } ResumeForm(); }; tsMain.Items.Add(tsbBorderColor); tsbFillColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Fill_color___); tsbFillColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbFillColor.Click += (sender, e) => { PauseForm(); ShapeType shapeType = CurrentShapeType; Color fillColor; if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon) { fillColor = AnnotationOptions.TextFillColor; } else if (shapeType == ShapeType.DrawingStep) { fillColor = AnnotationOptions.StepFillColor; } else { fillColor = AnnotationOptions.FillColor; } if (ColorPickerForm.PickColor(fillColor, out Color newColor)) { if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextFillColor = newColor; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepFillColor = newColor; } else { AnnotationOptions.FillColor = newColor; } UpdateMenu(); UpdateCurrentShape(); } ResumeForm(); }; tsMain.Items.Add(tsbFillColor); tsbHighlightColor = new ToolStripButton(Resources.ShapeManager_CreateContextMenu_Highlight_color___); tsbHighlightColor.DisplayStyle = ToolStripItemDisplayStyle.Image; tsbHighlightColor.Click += (sender, e) => { PauseForm(); if (ColorPickerForm.PickColor(AnnotationOptions.HighlightColor, out Color newColor)) { AnnotationOptions.HighlightColor = newColor; UpdateMenu(); UpdateCurrentShape(); } ResumeForm(); }; tsMain.Items.Add(tsbHighlightColor); tsddbShapeOptions = new ToolStripDropDownButton(Resources.ShapeManager_CreateToolbar_ShapeOptions); tsddbShapeOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbShapeOptions.Image = Resources.layer__pencil; tsMain.Items.Add(tsddbShapeOptions); tslnudBorderSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Border_size_); tslnudBorderSize.Content.Minimum = 0; tslnudBorderSize.Content.Maximum = 20; tslnudBorderSize.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; int borderSize = (int)tslnudBorderSize.Content.Value; if (shapeType == ShapeType.DrawingTextBackground || shapeType == ShapeType.DrawingSpeechBalloon) { AnnotationOptions.TextBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingTextOutline) { AnnotationOptions.TextOutlineBorderSize = borderSize; } else if (shapeType == ShapeType.DrawingStep) { AnnotationOptions.StepBorderSize = borderSize; } else { AnnotationOptions.BorderSize = borderSize; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBorderSize); tslnudCornerRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Corner_radius_); tslnudCornerRadius.Content.Minimum = 0; tslnudCornerRadius.Content.Maximum = 150; tslnudCornerRadius.Content.ValueChanged = (sender, e) => { ShapeType shapeType = CurrentShapeType; if (shapeType == ShapeType.RegionRectangle) { AnnotationOptions.RegionCornerRadius = (int)tslnudCornerRadius.Content.Value; } else if (shapeType == ShapeType.DrawingRectangle || shapeType == ShapeType.DrawingTextBackground) { AnnotationOptions.DrawingCornerRadius = (int)tslnudCornerRadius.Content.Value; } UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudCornerRadius); tslnudBlurRadius = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Blur_radius_); tslnudBlurRadius.Content.Minimum = 3; tslnudBlurRadius.Content.Maximum = 199; tslnudBlurRadius.Content.Increment = 2; tslnudBlurRadius.Content.ValueChanged = (sender, e) => { AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudBlurRadius); tslnudPixelateSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Pixel_size_); tslnudPixelateSize.Content.Minimum = 2; tslnudPixelateSize.Content.Maximum = 10000; tslnudPixelateSize.Content.ValueChanged = (sender, e) => { AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudPixelateSize); tslnudCenterPoints = new ToolStripLabeledNumericUpDown("Center points:"); tslnudCenterPoints.Content.Minimum = 0; tslnudCenterPoints.Content.Maximum = LineDrawingShape.MaximumCenterPointCount; tslnudCenterPoints.Content.ValueChanged = (sender, e) => { AnnotationOptions.LineCenterPointCount = (int)tslnudCenterPoints.Content.Value; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tslnudCenterPoints); tsmiArrowHeadsBothSide = new ToolStripMenuItem("Arrow heads in both side"); tsmiArrowHeadsBothSide.CheckOnClick = true; tsmiArrowHeadsBothSide.Click += (sender, e) => { AnnotationOptions.ArrowHeadsBothSide = tsmiArrowHeadsBothSide.Checked; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tsmiArrowHeadsBothSide); tsmiShadow = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_DropShadow); tsmiShadow.Checked = true; tsmiShadow.CheckOnClick = true; tsmiShadow.Click += (sender, e) => { AnnotationOptions.Shadow = tsmiShadow.Checked; UpdateCurrentShape(); }; tsddbShapeOptions.DropDownItems.Add(tsmiShadow); // In dropdown menu if only last item is visible then menu opens at 0, 0 position on first open, so need to add dummy item to solve this weird bug... tsddbShapeOptions.DropDownItems.Add(new ToolStripSeparator() { Visible = false }); #endregion Shape options #region Edit ToolStripDropDownButton tsddbEdit = new ToolStripDropDownButton(Resources.ShapeManager_CreateToolbar_Edit); tsddbEdit.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbEdit.Image = Resources.wrench_screwdriver; tsMain.Items.Add(tsddbEdit); tsmiUndo = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_Undo); tsmiUndo.Image = Resources.arrow_circle_225_left; tsmiUndo.ShortcutKeyDisplayString = "Ctrl+Z"; tsmiUndo.MouseDown += (sender, e) => UndoShape(); tsddbEdit.DropDownItems.Add(tsmiUndo); tsddbEdit.DropDownItems.Add(new ToolStripSeparator()); tsmiDelete = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_Delete); tsmiDelete.Image = Resources.layer__minus; tsmiDelete.ShortcutKeyDisplayString = "Del"; tsmiDelete.MouseDown += (sender, e) => DeleteCurrentShape(); tsddbEdit.DropDownItems.Add(tsmiDelete); tsmiDeleteAll = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_DeleteAll); tsmiDeleteAll.Image = Resources.eraser; tsmiDeleteAll.ShortcutKeyDisplayString = "Shift+Del"; tsmiDeleteAll.MouseDown += (sender, e) => DeleteAllShapes(); tsddbEdit.DropDownItems.Add(tsmiDeleteAll); tsddbEdit.DropDownItems.Add(new ToolStripSeparator()); tsmiMoveTop = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_BringToFront); tsmiMoveTop.Image = Resources.layers_stack_arrange; tsmiMoveTop.ShortcutKeyDisplayString = "Home"; tsmiMoveTop.MouseDown += (sender, e) => MoveCurrentShapeTop(); tsddbEdit.DropDownItems.Add(tsmiMoveTop); tsmiMoveUp = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_BringForward); tsmiMoveUp.Image = Resources.layers_arrange; tsmiMoveUp.ShortcutKeyDisplayString = "Page up"; tsmiMoveUp.MouseDown += (sender, e) => MoveCurrentShapeUp(); tsddbEdit.DropDownItems.Add(tsmiMoveUp); tsmiMoveDown = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_SendBackward); tsmiMoveDown.Image = Resources.layers_arrange_back; tsmiMoveDown.ShortcutKeyDisplayString = "Page down"; tsmiMoveDown.MouseDown += (sender, e) => MoveCurrentShapeDown(); tsddbEdit.DropDownItems.Add(tsmiMoveDown); tsmiMoveBottom = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_SendToBack); tsmiMoveBottom.Image = Resources.layers_stack_arrange_back; tsmiMoveBottom.ShortcutKeyDisplayString = "End"; tsmiMoveBottom.MouseDown += (sender, e) => MoveCurrentShapeBottom(); tsddbEdit.DropDownItems.Add(tsmiMoveBottom); #endregion Edit if (!form.IsEditorMode) { tsMain.Items.Add(new ToolStripSeparator()); #region Capture ToolStripDropDownButton tsddbCapture = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Capture); tsddbCapture.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbCapture.Image = Resources.camera; tsMain.Items.Add(tsddbCapture); tsmiRegionCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_CaptureRegions); tsmiRegionCapture.Image = Resources.layer; tsmiRegionCapture.ShortcutKeyDisplayString = "Enter"; tsmiRegionCapture.MouseDown += (sender, e) => { form.UpdateRegionPath(); form.Close(RegionResult.Region); }; tsddbCapture.DropDownItems.Add(tsmiRegionCapture); if (RegionCaptureForm.LastRegionFillPath != null) { ToolStripMenuItem tsmiLastRegionCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateToolbar_LastRegion); tsmiLastRegionCapture.Image = Resources.layers; tsmiLastRegionCapture.MouseDown += (sender, e) => form.Close(RegionResult.LastRegion); tsddbCapture.DropDownItems.Add(tsmiLastRegionCapture); } ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_fullscreen); tsmiFullscreenCapture.Image = Resources.layer_fullscreen; tsmiFullscreenCapture.ShortcutKeyDisplayString = "Space"; tsmiFullscreenCapture.MouseDown += (sender, e) => form.Close(RegionResult.Fullscreen); tsddbCapture.DropDownItems.Add(tsmiFullscreenCapture); ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_active_monitor); tsmiActiveMonitorCapture.Image = Resources.monitor; tsmiActiveMonitorCapture.ShortcutKeyDisplayString = "~"; tsmiActiveMonitorCapture.MouseDown += (sender, e) => form.Close(RegionResult.ActiveMonitor); tsddbCapture.DropDownItems.Add(tsmiActiveMonitorCapture); ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Capture_monitor); tsmiMonitorCapture.HideImageMargin(); tsmiMonitorCapture.Image = Resources.monitor_window; tsddbCapture.DropDownItems.Add(tsmiMonitorCapture); Screen[] screens = Screen.AllScreens; for (int i = 0; i < screens.Length; i++) { Screen screen = screens[i]; ToolStripMenuItem tsmi = new ToolStripMenuItem($"{screen.Bounds.Width}x{screen.Bounds.Height}"); tsmi.ShortcutKeyDisplayString = (i + 1).ToString(); int index = i; tsmi.MouseDown += (sender, e) => { form.MonitorIndex = index; form.Close(RegionResult.Monitor); }; tsmiMonitorCapture.DropDownItems.Add(tsmi); } #endregion Capture #region Options ToolStripDropDownButton tsddbOptions = new ToolStripDropDownButton(Resources.ShapeManager_CreateContextMenu_Options); tsddbOptions.DisplayStyle = ToolStripItemDisplayStyle.Image; tsddbOptions.Image = Resources.gear; tsMain.Items.Add(tsddbOptions); tsmiQuickCrop = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Multi_region_mode); tsmiQuickCrop.Checked = !Config.QuickCrop; tsmiQuickCrop.CheckOnClick = true; tsmiQuickCrop.ShortcutKeyDisplayString = "Q"; tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked; tsddbOptions.DropDownItems.Add(tsmiQuickCrop); tsmiTips = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_tips); tsmiTips.Checked = Config.ShowHotkeys; tsmiTips.CheckOnClick = true; tsmiTips.ShortcutKeyDisplayString = "F1"; tsmiTips.Click += (sender, e) => Config.ShowHotkeys = tsmiTips.Checked; tsddbOptions.DropDownItems.Add(tsmiTips); ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_position_and_size_info); tsmiShowInfo.Checked = Config.ShowInfo; tsmiShowInfo.CheckOnClick = true; tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked; tsddbOptions.DropDownItems.Add(tsmiShowInfo); ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_magnifier); tsmiShowMagnifier.Checked = Config.ShowMagnifier; tsmiShowMagnifier.CheckOnClick = true; tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiShowMagnifier); ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Square_shape_magnifier); tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier; tsmiUseSquareMagnifier.CheckOnClick = true; tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked; tsddbOptions.DropDownItems.Add(tsmiUseSquareMagnifier); ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_count_); tslnudMagnifierPixelCount.Content.Minimum = RegionCaptureOptions.MagnifierPixelCountMinimum; tslnudMagnifierPixelCount.Content.Maximum = RegionCaptureOptions.MagnifierPixelCountMaximum; tslnudMagnifierPixelCount.Content.Increment = 2; tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount; tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelCount); ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Magnifier_pixel_size_); tslnudMagnifierPixelSize.Content.Minimum = RegionCaptureOptions.MagnifierPixelSizeMinimum; tslnudMagnifierPixelSize.Content.Maximum = RegionCaptureOptions.MagnifierPixelSizeMaximum; tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize; tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value; tsddbOptions.DropDownItems.Add(tslnudMagnifierPixelSize); ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_screen_wide_crosshair); tsmiShowCrosshair.Checked = Config.ShowCrosshair; tsmiShowCrosshair.CheckOnClick = true; tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked; tsddbOptions.DropDownItems.Add(tsmiShowCrosshair); ToolStripMenuItem tsmiEnableAnimations = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_EnableAnimations); tsmiEnableAnimations.Checked = Config.EnableAnimations; tsmiEnableAnimations.CheckOnClick = true; tsmiEnableAnimations.Click += (sender, e) => Config.EnableAnimations = tsmiEnableAnimations.Checked; tsddbOptions.DropDownItems.Add(tsmiEnableAnimations); ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Fixed_size_region_mode); tsmiFixedSize.Checked = Config.IsFixedSize; tsmiFixedSize.CheckOnClick = true; tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked; tsddbOptions.DropDownItems.Add(tsmiFixedSize); ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown(Resources.ShapeManager_CreateContextMenu_Width_, Resources.ShapeManager_CreateContextMenu_Height_); tslnudFixedSize.Content.Minimum = 10; tslnudFixedSize.Content.Maximum = 10000; tslnudFixedSize.Content.Increment = 10; tslnudFixedSize.Content.Value = Config.FixedSize.Width; tslnudFixedSize.Content.Value2 = Config.FixedSize.Height; tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2); tsddbOptions.DropDownItems.Add(tslnudFixedSize); ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_Show_FPS); tsmiShowFPS.Checked = Config.ShowFPS; tsmiShowFPS.CheckOnClick = true; tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked; tsddbOptions.DropDownItems.Add(tsmiShowFPS); ToolStripMenuItem tsmiRememberMenuState = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_RememberMenuState); tsmiRememberMenuState.Checked = Config.RememberMenuState; tsmiRememberMenuState.CheckOnClick = true; tsmiRememberMenuState.Click += (sender, e) => Config.RememberMenuState = tsmiRememberMenuState.Checked; tsddbOptions.DropDownItems.Add(tsmiRememberMenuState); #endregion Options } ToolStripLabel tslDragRight = new ToolStripLabel() { Alignment = ToolStripItemAlignment.Right, DisplayStyle = ToolStripItemDisplayStyle.Image, Image = Resources.ui_radio_button_uncheck, Margin = new Padding(0, 0, 2, 0), Padding = new Padding(2) }; tsMain.Items.Add(tslDragRight); tslDragLeft.MouseDown += TslDrag_MouseDown; tslDragRight.MouseDown += TslDrag_MouseDown; tslDragLeft.MouseEnter += TslDrag_MouseEnter; tslDragRight.MouseEnter += TslDrag_MouseEnter; tslDragLeft.MouseLeave += TslDrag_MouseLeave; tslDragRight.MouseLeave += TslDrag_MouseLeave; foreach (ToolStripItem tsi in tsMain.Items.OfType <ToolStripItem>()) { if (!string.IsNullOrEmpty(tsi.Text)) { tsi.MouseEnter += (sender, e) => { Point pos = CaptureHelpers.ScreenToClient(menuForm.PointToScreen(tsi.Bounds.Location)); pos.Y += tsi.Height + 8; MenuTextAnimation.Text = tsi.Text; MenuTextAnimation.Position = pos; MenuTextAnimation.Start(); }; tsi.MouseLeave += TsMain_MouseLeave; } } tsMain.ResumeLayout(false); tsMain.PerformLayout(); menuForm.ResumeLayout(false); menuForm.Show(form); UpdateMenu(); CurrentShapeChanged += shape => UpdateMenu(); CurrentShapeTypeChanged += shapeType => UpdateMenu(); ShapeCreated += shape => UpdateMenu(); ConfigureMenuState(); form.Activate(); }
private void ColorGradientChip_MouseUp(object sender, MouseEventArgs e) { if (this._mouseDrag != null) { this._mouseDrag = null; if (Math.Abs(e.Y) > 20) { //TODO: remove chip if (this.Removed != null) this.Removed(this, null); } else if (this._draggedDistance < 2) { ColorPickerForm form = new ColorPickerForm(); form.Show(); form.SetStartPositionRelativeLoc(null); form.ColorObject = this.ColorObject; form.ColorChanged += new EventHandler(form_ColorChanged); } } }