private void ContextMenu_Popup(System.Object sender, System.EventArgs e) { System.Drawing.Point point = System.Windows.Forms.Control.MousePosition; var cor = scintilla1.PointToClient(point); var pos = scintilla1.CharPositionFromPoint(cor.X, cor.Y); Console.WriteLine("start"); int startPos = ValueStartPosition(pos); Console.WriteLine("start2"); Console.WriteLine("end"); int endPos = ValueEndPosition(pos); Console.WriteLine("end3"); string text = scintilla1.GetTextRange(startPos, endPos - startPos); scintilla1.ContextMenu.MenuItems.Clear(); scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Copy", (s, ea) => { if (scintilla1.SelectedText != "") { scintilla1.Copy(); } else { scintilla1.CopyRange(startPos, endPos); } })); scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Select All", (s, ea) => scintilla1.SelectAll())); if ((text.StartsWith("http://") || text.StartsWith("https://"))) { scintilla1.ContextMenu.MenuItems.Add("-"); scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Open in Browser", (s, ea) => Process.Start(text))); if (text.EndsWith(".jpg") || text.EndsWith(".png")) { scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Open Image in new Window", (s, ea) => { new ImageViewer(text).ShowDialog(); })); scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Save Image", (s, ea) => { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.RestoreDirectory = true; saveFileDialog1.FileName = text.Split('/').Last(); saveFileDialog1.Filter = "Image Files|*." + text.Split('.').Last(); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (var webClient = new WebClient()) { webClient.DownloadFile(text, saveFileDialog1.FileName); } } })); } } }