示例#1
0
        private void ContextMenu_Popup(System.Object sender, System.EventArgs e)
        {
            scintilla1.ContextMenu.MenuItems.Clear();

            scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Copy", (s, ea) => scintilla1.Copy()));
            scintilla1.ContextMenu.MenuItems.Add(new MenuItem("Select All", (s, ea) => scintilla1.SelectAll()));



            System.Drawing.Point point = System.Windows.Forms.Control.MousePosition;
            var cor = scintilla1.PointToClient(point);
            var pos = scintilla1.CharPositionFromPoint(cor.X, cor.Y);

            int startPos = ValueStartPosition(pos);
            int endPos   = ValueEndPosition(pos);

            string text = scintilla1.GetTextRange(startPos, endPos - startPos);

            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);
                            }
                        }
                    }));
                }
            }
        }
        public virtual void MoveFormAwayFromSelection()
        {
            if (!Visible)
            {
                return;
            }

            if (!AutoPosition)
            {
                return;
            }

            int pos = Scintilla.Caret.Position;
            int x   = Scintilla.PointXFromPosition(pos);
            int y   = Scintilla.PointYFromPosition(pos);

            Point cursorPoint = Scintilla.PointToScreen(new Point(x, y));

            Rectangle r = new Rectangle(Location, Size);

            if (r.Contains(cursorPoint))
            {
                Point newLocation;
                if (cursorPoint.Y < (Screen.PrimaryScreen.Bounds.Height / 2))
                {
                    // Top half of the screen
                    newLocation = Scintilla.PointToClient(
                        new Point(Location.X, cursorPoint.Y + Scintilla.Lines.Current.Height * 2)
                        );
                }
                else
                {
                    // Bottom half of the screen
                    newLocation = Scintilla.PointToClient(
                        new Point(Location.X, cursorPoint.Y - Height - (Scintilla.Lines.Current.Height * 2))
                        );
                }
                newLocation = Scintilla.PointToScreen(newLocation);
                Location    = newLocation;
            }
        }