/// <summary> /// Sets a default <see cref="ContextMenuStrip"/> to this /// <see cref="RichTextBox"/> with cut, copy, paste, select all, load file, /// save file and undo. /// </summary> /// <param name="richTextBox"> /// The <see cref="RichTextBox"/> control to add the /// <see cref="ContextMenuStrip"/>. /// </param> /// <param name="owner"> /// An implementation of <see cref="IWin32Window"/> that will own modal dialog /// boxes. /// </param> public static void SetDefaultContextMenuStrip(this RichTextBox richTextBox, IWin32Window owner = null) { if (richTextBox is not { } rtb) { return; } var cms = new ContextMenuStrip { AutoSize = true, RenderMode = ToolStripRenderMode.System, ShowImageMargin = false }; cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.Cut), rtb.Cut); cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.Copy), rtb.Copy); cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.Paste), rtb.Paste); cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.SelectAll), rtb.SelectAll); cms.Items.Add(new ToolStripSeparator()); cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.LoadFile), LoadTextFile, rtb, owner); cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.SaveAll), SaveTextFile, rtb, owner); cms.Items.Add(new ToolStripSeparator()); cms.AddToolStripItem(new ToolStripMenuItem(UIStrings.Undo), rtb.Undo); rtb.ContextMenuStrip = cms; }