示例#1
0
        public Point GetCursorPoint(Marker marker)
        {
            PictureBox pictureBox = (marker.Parent as PictureBox);
            Point      point      = new Point();

            point.X = Cursor.Position.X - pictureBox.PointToScreen(Point.Empty).X;
            point.Y = Cursor.Position.Y - pictureBox.PointToScreen(Point.Empty).Y;

            return(point);
        }
示例#2
0
        private void LineMouseUp(object sender)
        {
            Pen        p      = new Pen(Color.Blue, 2);
            PictureBox picBox = sender as PictureBox;

            if (picBox.Image == null)
            {
                Bitmap bmp = new Bitmap(picBox.Width, picBox.Height);
                picBox.Image = bmp;
            }

            ControlPaint.DrawReversibleLine(picBox.PointToScreen(pointStart), picBox.PointToScreen(pointEnd), Color.Black);
            using (Graphics g = Graphics.FromImage(picBox.Image))
                g.DrawLine(p, pointStart, pointEnd);

            picBox.Invalidate();
        }
示例#3
0
        // 메뉴
        private void picMenu_Click(object sender, EventArgs e)
        {
            PictureBox btnSender   = (PictureBox)sender;
            Point      ptLowerLeft = new Point(0, btnSender.Height);

            ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
            cmsMenu.Show(ptLowerLeft);
        }
示例#4
0
        //Profile drop-down menu
        private void ProfilePictureBox_Click(object sender, EventArgs e)
        {
            PictureBox btnSender   = (PictureBox)sender;
            Point      ptLowerLeft = new Point(0, btnSender.Height);

            ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
            LoginMenuStrip.Show(ptLowerLeft);
        }
示例#5
0
        void picBoxSettings_MouseClick(object sender, MouseEventArgs e)
        {
            PictureBox btnSender   = (PictureBox)sender;
            Point      ptLowerLeft = new Point(0, btnSender.Height);

            ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
            contextMenuStrip1.Show(ptLowerLeft);
        }
示例#6
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            PictureBox Sender      = (PictureBox)sender;
            Point      ptLowerLeft = new Point(0, Sender.Height);

            ptLowerLeft = Sender.PointToScreen(ptLowerLeft);
            MSuserAction.Show(ptLowerLeft);
        }
示例#7
0
        private void Control_MouseClick(object sender, MouseEventArgs e)
        {
            Point point = (sender is PictureBox ? _pictureBoxThumbnail.PointToScreen(e.Location)
                                : (sender is Label ? _labelFileName.PointToScreen(e.Location)
                                        : PointToScreen(e.Location)));

            RaiseThumbnailClickedEvent(new MouseEventArgs(e.Button, e.Clicks, point.X, point.Y, e.Delta));
        }
示例#8
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            PictureBox btnSender   = (PictureBox)sender;
            Point      ptLowerLeft = new Point(btnSender.Width, btnSender.Height);

            ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
            contextMenuStrip1.Show(ptLowerLeft);
        }
        private void SetRoi(object sender, Rectangle rect)
        {
            PictureBox pb    = sender as PictureBox;
            Point      start = pb.PointToScreen(pb.Location);

            double xoffset = (rect.Location.X > start.X) ? (double)(rect.Location.X - start.X) / pb.Width : 0;
            double yoffset = (rect.Location.Y > start.Y) ? (double)(rect.Location.Y - start.Y) / pb.Height : 0;
            //UC_CameraCtrl.SetRoi(xoffset, yoffset, (double)rect.Width/pb.Width, (double)rect.Height/pb.Height);
        }
示例#10
0
 private void Favorites_btn_Click(object sender, EventArgs e)
 {
     if (!myFavoritesContextMenuStrip.Visible)
     {
         PictureBox btnSender   = (PictureBox)sender;
         Point      ptLowerLeft = new Point(0, btnSender.Height);
         ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
         myFavoritesContextMenuStrip.Show(ptLowerLeft);
     }
 }
示例#11
0
        private void People_btn_Click(object sender, EventArgs e)
        {
            if (accForm.tmpUsername == "")
            {
                return;
            }

            if (!peopleMenuStrip.Visible)
            {
                PictureBox btnSender   = (PictureBox)sender;
                Point      ptLowerLeft = new Point(0, btnSender.Height);
                ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
                peopleMenuStrip.Show(ptLowerLeft);
            }
        }
示例#12
0
 private void joystickMouseMoveHandler(MouseEventArgs e, Point location, PictureBox box, Action <int, int> stickObserver)
 {
     if (MathLibrary.isPointInCircle(e.X, e.Y, joystickR, joystickR, joystickR))
     {
         location = e.Location;
         box.Invalidate();
         if (enabledStick)
         {
             stickObserver((int)Math.Floor((e.X - joystickR) / ((double)joystickR / 100)), (int)Math.Floor((e.Y - joystickR) / ((double)joystickR / 100)));
         }
     }
     else
     {
         Cursor.Position = box.PointToScreen(MathLibrary.convertPointToCircle(e.X, e.Y, joystickR, joystickR, joystickR - 2));
     }
 }
        /// <summary>
        /// Load Image to picture box from file that user choises.
        /// </summary>
        /// <param name="pictureBox">The picture box to save its image</param>
        /// <param name="filter">The filter to be used to get type of images. example ("PNG Files|*.png|BMP Files|*.bmp")</param>
        /// <param name="saveDialogTitle">The title for the save dialog appears for the user.</param>
        public static void SaveImageInFile(this PictureBox pictureBox, string filter, string saveDialogTitle)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Title    = saveDialogTitle;
            saveFileDialog.Filter   = filter;
            saveFileDialog.FileName = "";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                var s              = pictureBox.Size;
                var memoryImage    = new Bitmap(s.Width, s.Height);
                var memoryGraphics = Graphics.FromImage(memoryImage);
                var screenPos      = pictureBox.PointToScreen(new Point(0, 0));
                memoryGraphics.CopyFromScreen(screenPos.X, screenPos.Y, 0, 0, s);
                memoryImage.Save(saveFileDialog.FileName);
            }
        }
示例#14
0
        void TakeScreenshot()
        {
            string DeleteDir = Application.StartupPath + "\\resim.png";

            File.Delete(DeleteDir);
            Point picpoint      = PictureBox.PointToScreen(new Point(0, 0));
            var   bmpScreenshot = new Bitmap(PictureBox.Size.Width,
                                             PictureBox.Size.Height,
                                             PixelFormat.Format32bppArgb);
            var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            gfxScreenshot.CopyFromScreen(picpoint.X,
                                         picpoint.Y,
                                         0,
                                         0,
                                         PictureBox.Size,
                                         CopyPixelOperation.SourceCopy);
            bmpScreenshot.Save(DeleteDir, System.Drawing.Imaging.ImageFormat.Png);
        }
示例#15
0
        //przechwycenie do pamięci pojedynczej klatki filmu
        internal MemoryStream Grab()
        {
            //utworzenie intasncji klasy MemorySteram
            MemoryStream ms = new MemoryStream();
            //utowrzenie klasy bitmap o zadanych wymiarach
            Bitmap bitmap = new Bitmap(p_preview.Width, p_preview.Height);
            //utworzenie instancji klasy GRapihics na podstawie klasy bitmap
            Graphics g = Graphics.FromImage(bitmap);
            //utworzenie instncji klasy kwadratu no podstawie wymiarów okna podglądu
            Rectangle rectanglePanelVideoPreview = p_preview.Bounds;
            // odnalezienie punktu na ekranie z oknem podglądu
            Point sourcePoints = p_preview.PointToScreen(new Point(p_preview.ClientRectangle.X, p_preview.ClientRectangle.Y));

            //kopiowanie fragmentu obrazu z ekranu
            g.CopyFromScreen(sourcePoints, Point.Empty, rectanglePanelVideoPreview.Size);
            //zapis tego obrazu do ms
            bitmap.Save(ms, ImageFormat.Jpeg);
            return(ms);
        }
示例#16
0
        void picBox_MouseMove(object sender, MouseEventArgs e)
        {
            if ((DateTime.Now - dt).TotalMilliseconds < 5 || picBox.Image == null)
            {
                return;
            }
            dt = DateTime.Now;
            Point p           = e.Location;
            Point screenPoint = picBox.PointToScreen(p);
            Point loc         = new Point(screenPoint.X - formMagnifier.Width / 2, screenPoint.Y - formMagnifier.Height / 2);

            formMagnifier.Location = loc;
            PropertyInfo _ImageRectanglePropert = picBox.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
            Rectangle    _Rectangle             = (Rectangle)_ImageRectanglePropert.GetValue(picBox, null);

            float wR = (float)picBox.Image.Width / (float)_Rectangle.Width;

            bitmap = new Bitmap((int)(100 * wR), (int)(100 * wR));
            float l = 0, t = 0;

            if (_Rectangle.Left > 0)
            {
                l = (p.X - _Rectangle.Left - 50) * wR;
                t = (p.Y - 50) * wR;
            }
            if (_Rectangle.Top > 0)
            {
                l = (p.X - 50) * wR;
                t = (p.Y - _Rectangle.Top - 50) * wR;
            }
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(picBox.Image, new RectangleF(0, 0, 100 * wR, 100 * wR), new RectangleF(l, t, 100 * wR, 100 * wR), GraphicsUnit.Pixel);
                g.DrawImage(mImageMagnifier, 0, 0, bitmap.Width, bitmap.Height);
            }
            picShow.Image = bitmap;
        }
示例#17
0
 public Point PointToScreen(Point p)
 {
     return(m_pictureBox.PointToScreen(p));
 }
示例#18
0
 public void SetCursorInMiddle()
 {
     Cursor.Position = _box.PointToScreen(new Point(_box.Width / 2, _box.Height / 2));
 }
        private void AlterButton_Click(object sender, EventArgs e)
        {
            //The code in this function is discgusting and almost getting to the point of spaghetti code
            //Shits getting hard to keep track of and needs to be optimised
            //Grabs the point on the picturebox the right click was made
            RightClickContextMenu rcm = new RightClickContextMenu();
            PictureBox            pic = new PictureBox();
            double percentageOfZoom   = 0;
            double xCoordinate        = 0;
            double yCoordinate        = 0;

            foreach (NewTabPage t in tabLst)
            {
                if (t.tabName == tabControlDesignerView.SelectedTab.Text)
                {
                    pic = t.picBox;
                    percentageOfZoom = t.percentageOfZoom;
                    break;
                }
            }

            foreach (RightClickContextMenu r in cmLst)
            {
                if (r.Name == tabControlDesignerView.SelectedTab.Text)
                {
                    xCoordinate = r.p.X;
                    yCoordinate = r.p.Y;
                    break;
                }
            }

            //Maybe I should put this in its own fuction seen as it's repeated so many times
            var   screenPosition = pic.PointToScreen(new Point(0, 0));
            Point p = new Point((int)((xCoordinate - screenPosition.X) / (percentageOfZoom / 100)), (int)((yCoordinate - screenPosition.Y) / (percentageOfZoom / 100)));

            DetectIfPointIsInside detectIfPoint = new DetectIfPointIsInside(projectDisplaySize.Width);

            if (p != null && p != new Point(0, 0))
            {
                foreach (DisplayPage d in pageLst)
                {
                    if (d.displayPageName == tabControlDesignerView.SelectedTab.Text)
                    {
                        foreach (CustomButton c in d.GetButtonList())
                        {
                            if (detectIfPoint.DoesIntersect(c.GetPoly(), c.GetPoly().Length, p))
                            {
                                c.SetPageLink(GetSelectedPage());
                                break;
                            }
                        }

                        foreach (CircleButton c in d.GetCircleBtnLst())
                        {
                            if (detectIfPoint.DoesIntersectCircle(c.GetRadius(), p, c.GetCentre()))
                            {
                                c.SetPageLink(GetSelectedPage());;
                                break;
                            }
                        }
                        break;
                    }
                }
            }

            else
            {
                MessageBox.Show("Error could not find the point the right click was made",
                                "INTERNAL ERROR",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
            }
        }
        private void PictureBox_Click(object sender, MouseEventArgs e)
        {
            //Used to check how close the click is to the first point
            DetectIfPointIsInside ifPointIsInside = new DetectIfPointIsInside(((PictureBox)sender).Width);
            bool doesIntersect = false;

            //Gets the position of the mouse cursor inside the picturebox
            PictureBox pic              = (PictureBox)sender;
            var        screenPosition   = pic.PointToScreen(new Point(0, 0));
            double     percentageOfZoom = 0;

            //Grbs the percentage of zoom from the tab page
            foreach (NewTabPage t in tabLst)
            {
                if (t.tabName == pic.Name)
                {
                    percentageOfZoom = t.percentageOfZoom;
                    break;
                }
            }

            //Maybe I should put this in its own fuction seen as it's repeated so many times
            double xCoordinate = Cursor.Position.X;
            double yCoordinate = Cursor.Position.Y;
            Point  cP          = new Point((int)((xCoordinate - screenPosition.X) / (percentageOfZoom / 100)), (int)((yCoordinate - screenPosition.Y) / (percentageOfZoom / 100)));

            foreach (DisplayPage d in pageLst)
            {
                if (d.displayPageName == ((PictureBox)sender).Name)
                {
                    foreach (CustomButton b in d.GetButtonList())
                    {
                        if (ifPointIsInside.DoesIntersect(b.GetPoly(), b.GetPoly().Length, cP))
                        {
                            doesIntersect = true;
                        }
                    }
                    foreach (CircleButton c in d.GetCircleBtnLst())
                    {
                        if (ifPointIsInside.DoesIntersectCircle(c.GetRadius(), cP, c.GetCentre()))
                        {
                            doesIntersect = true;
                        }
                    }
                    //Detects if the new line intersects with any of the others
                    if (d.GetCurrentButton().Count > 2)
                    {
                        for (int i = 0; i < d.GetCurrentButton().Count - 2; i++)
                        {
                            int next = (i + 1) % d.GetCurrentButton().Count;

                            if (ifPointIsInside.doIntersect(d.GetCurrentButton()[i], d.GetCurrentButton()[next], cP, d.GetCurrentButton()[d.GetCurrentButton().Count - 1]))
                            {
                                if (ifPointIsInside.orientation(d.GetCurrentButton()[i], cP, d.GetCurrentButton()[next]) == 0)
                                {
                                    doesIntersect = ifPointIsInside.OnSegment(d.GetCurrentButton()[i], cP, d.GetCurrentButton()[next]);
                                }
                                else
                                {
                                    doesIntersect = true;
                                }
                            }
                        }
                    }

                    if (!doesIntersect)
                    {
                        //Finds if the click is within 5px of the first point
                        //If true, the button is complete
                        if (isCreatingButton == true)
                        {
                            if (d.GetCurrentButton().Count != 0)
                            {
                                if (!ifPointIsInside.DoesIntersectCircle(5, cP, d.GetCurrentButton()[0]))
                                {
                                    d.AddPointToCurrentButton(cP);
                                }
                                else
                                {
                                    isCreatingButton  = false;
                                    btnFinish.Visible = false;
                                    btnCancel.Visible = false;
                                    break;
                                }
                            }

                            else
                            {
                                d.AddPointToCurrentButton(cP);
                                break;
                            }
                        }

                        if (isCreatingButton == false)
                        {
                            if (d.displayPageName == ((PictureBox)sender).Name)
                            {
                                d.FinishButton(currentButtonType, GetSelectedPage());
                            }

                            isCreatingButton = null;
                            break;
                        }

                        if (d.displayPageName == ((PictureBox)sender).Name && d.isCreatingCircle == true)
                        {
                            Point c = new Point((int)(cP.X - (r / 2)), (int)(cP.Y - (r / 2)));
                            d.isCreatingCircle = false;
                            d.AddCircleButton(c, r, GetSelectedPage());
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Buttons cannot intersect",
                                        "Button create error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1);
                        break;
                    }
                }
            }
        }
示例#21
0
        void SetupEventHandlers()
        {
            // Eventhandler to begin/end creating a rectangle for clips.
            previewPicBox.Click += delegate(object sender, EventArgs e)
            {
                isCreatingRect = !isCreatingRect;
                if (isCreatingRect)
                {
                    beginRectPt = previewPicBox.PointToClient(new Point(MousePosition.X, MousePosition.Y));
                }
            };

            // Eventhandler to resize rectangle.
            previewPicBox.MouseMove += delegate(object sender, MouseEventArgs ma)
            {
                if (isCreatingRect)
                {
                    endRectPt = new Point(ma.X, ma.Y);
                    previewPicBox.Invalidate(Rectangle.Empty, false);
                }
            };

            previewPicBox.Paint += delegate(object sender, PaintEventArgs pea)
            {
                currentClipRect = RectFromMinMax(beginRectPt, endRectPt);
                if (currentClipRect != Rectangle.Empty && previewPicBox.Image != null)
                {
                    Graphics g = pea.Graphics;
                    g.DrawRectangle(Pens.White, currentClipRect);
                }
            };

            composePnl.Click += delegate(object sender, EventArgs ea)
            {
                if (currentClipRect != Rectangle.Empty)
                {
                    PictureBox pb = GetPreviewImageSnapshot();

                    bool  isSelected = false; // Variable to check which pictureBox is selected by the user.
                    bool  isDragging = false; // Variable to controlling the dragging.
                    Point offset     = Point.Empty;

                    // Lets us start dragging the control around, and sends all others to the back.
                    pb.MouseDown += delegate(object s, MouseEventArgs ma)
                    {
                        isDragging = true;
                        offset     = ma.Location;

                        pb.BringToFront();
                        // Gives the controll Focus, which makes it possible for pb.GotFocus and LostFocus to execute.
                        pb.Focus();
                    };

                    pb.GotFocus += delegate(object s, EventArgs e)
                    {
                        isSelected = true;
                        pb.Invalidate();
                    };
                    pb.LostFocus += delegate(object s, EventArgs e) {
                        isSelected = false;
                        pb.Invalidate();
                    };

                    pb.Paint += delegate(object s, PaintEventArgs e)
                    {
                        if (isSelected)
                        {
                            // Draw a rectangle around the selected pictureBox in the composePnl.
                            e.Graphics.DrawRectangle(
                                Pens.Gold,
                                new Rectangle(
                                    pb.ClientRectangle.X,
                                    pb.ClientRectangle.Y,
                                    pb.ClientRectangle.Width - 1,
                                    pb.ClientRectangle.Height - 1
                                    )
                                );
                        }
                    };

                    // Stop dragging.
                    pb.MouseUp += delegate(object s, MouseEventArgs ma)
                    {
                        isDragging = false;
                        pb.Invalidate();
                    };

                    // Lets the user move the picturebox into its current location.
                    pb.MouseMove += delegate(object s, MouseEventArgs ma)
                    {
                        if (isDragging)
                        {
                            Point pos = composePnl.PointToClient(pb.PointToScreen(ma.Location));

                            pb.Location = new Point(pos.X - offset.X, pos.Y - offset.Y);
                        }
                    };

                    pb.PreviewKeyDown += delegate(object s, PreviewKeyDownEventArgs ke)
                    {
                        // Lets the user delete a picturebox in the List by pressing "Delete".
                        if (ke.KeyCode == Keys.Delete)
                        {
                            clips.Remove(pb);
                            composePnl.Controls.Remove(pb);
                        }
                    };

                    // Add clips to our clip list and the controls of the composePnl.
                    clips.Add(pb);
                    composePnl.Controls.Add(pb);
                    currentClipRect = Rectangle.Empty;
                    beginRectPt     = endRectPt = Point.Empty;
                }
            };
        }
        //Too much is being done here it's starting to lag after zooming in and out multiple times
        private void Timer_Tick(object sender, EventArgs e, PictureBox p, string path)
        {
            Timer  thisTimer        = (Timer)sender;
            Image  img              = null; //Needs to be updated so the user can input an image
            double percentageOfZoom = 0;

            foreach (DisplayPage d in pageLst)
            {
                if (d.displayPageName == (string)thisTimer.Tag)
                {
                    img = ResizeImage(d.GetBackgroundImage(), projectDisplaySize.Width, projectDisplaySize.Height); // otherwise if the background image was more than this then it wouldn't be able to properly place the buttons
                    break;
                }
            }
            Bitmap bmp = new Bitmap(img);

            if (autoSave == true && lastSave != null && (DateTime.Now - lastSave).Value.TotalSeconds >= 10)
            {
                Save();
            }

            //Grbs the percentage of zoom from the tab page
            foreach (NewTabPage t in tabLst)
            {
                if (t.tabName == p.Name)
                {
                    percentageOfZoom = t.percentageOfZoom;
                    break;
                }
            }

            if (tabControlDesignerView.SelectedTab.Text == p.Name)
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    Pen pen = new Pen(Color.Cyan, 2.0f);

                    foreach (DisplayPage d in pageLst)
                    {
                        if (d.displayPageName == p.Name)
                        {
                            foreach (CustomButton cB in d.GetButtonList())
                            {
                                for (int i = 1; i < cB.GetPoly().Count(); i++)
                                {
                                    g.DrawLine(pen, cB.GetPoly()[i - 1].X, cB.GetPoly()[i - 1].Y, cB.GetPoly()[i].X, cB.GetPoly()[i].Y);
                                }

                                if (cB.GetPoly().Count() <= 0)
                                {
                                    break;
                                }

                                g.DrawLine(pen, cB.GetPoly()[0].X, cB.GetPoly()[0].Y, cB.GetPoly()[cB.GetPoly().Count() - 1].X, cB.GetPoly()[cB.GetPoly().Count() - 1].Y);
                            }

                            foreach (Point point in d.GetCurrentButton())
                            {
                                for (int i = 1; i < d.GetCurrentButton().Count(); i++)
                                {
                                    g.DrawLine(pen, d.GetCurrentButton()[i - 1].X, d.GetCurrentButton()[i - 1].Y, d.GetCurrentButton()[i].X, d.GetCurrentButton()[i].Y);
                                }
                            }

                            foreach (CircleButton c in d.GetCircleBtnLst())
                            {
                                Point centre = c.GetCentre();
                                g.DrawEllipse(pen, centre.X, centre.Y, c.GetRadius(), c.GetRadius());
                            }

                            //Minus r (radius) from the position to the centre
                            if (d.isCreatingCircle == true)
                            {
                                var    screenPosition = p.PointToScreen(new Point(0, 0));
                                double xCoordinate    = Cursor.Position.X;
                                double yCoordinate    = Cursor.Position.Y;
                                Point  cP             = new Point((int)((xCoordinate - screenPosition.X) / (percentageOfZoom / 100)), (int)((yCoordinate - screenPosition.Y) / (percentageOfZoom / 100)));
                                g.DrawEllipse(pen, (int)(cP.X - (r / 2)), (int)(cP.Y - (r / 2)), r, r);
                            }
                        }
                    }
                }
            }

            //Delete the old bitmaps from memory
            GC.Collect();
            p.BackgroundImage = bmp;
        }
示例#23
0
        private Control CreateSplitBar()
        {
            var bar = new PictureBox()
            {
                Left = 0, Top = 300, Width = 400, Height = 6, Cursor = Cursors.SizeNS, Visible = false
            };

            Win32.SetParent(bar.Handle, nppData._nppHandle);
            bar.BringToFront();

            int preBarY  = 0,
                preScinH = 0,
                preSqlH  = 0;

            bar.MouseDown += (s, e) =>
            {
                if (e.Button != MouseButtons.Left)
                {
                    return;
                }
                isDrag  = true;
                preBarY = e.Y;
                RECT   recScin;
                IntPtr hndScin = GetCurrentScintilla();
                Win32.GetWindowRect(hndScin, out recScin);
                preScinH = recScin.Bottom - recScin.Top;
                preSqlH  = _currentCtr.Height;

                bar.BackColor = SystemColors.ActiveBorder;
                bar.BringToFront();
            };
            bar.MouseMove += (s, e) =>
            {
                if (!isDrag)
                {
                    return;
                }

                RECT   recScin;
                IntPtr hndScin = GetCurrentScintilla();
                Win32.GetWindowRect(hndScin, out recScin);
                var y = bar.Top + (e.Y - preBarY);
                if (bar.PointToScreen(new Point(0, y)).Y > recScin.Top + 100)
                {
                    bar.Top = y;
                }
                bar.BringToFront();
            };
            bar.MouseUp += (s, e) =>
            {
                if (!isDrag)
                {
                    return;
                }
                bar.BackColor = SystemColors.ButtonFace;
                bar.BringToFront();

                int key = _currentCtr.Handle.ToInt32();

                RECT   recScin;
                IntPtr hndScin = GetCurrentScintilla();
                Win32.GetWindowRect(hndScin, out recScin);

                IntPtr parent   = Win32.GetParent(hndScin); //actually parent is nppData._scintillaMainHandle
                Point  pRecScin = new Point(recScin.Left, recScin.Top);
                Win32.ScreenToClient(parent, ref pRecScin);

                int viewH = bar.Top - pRecScin.Y;
                int sqlH  = preSqlH + (preScinH - viewH);
                int width = recScin.Right - recScin.Left;
                Win32.SetWindowPos(hndScin, IntPtr.Zero, pRecScin.X, pRecScin.Y, width, viewH, SetWindowPosFlags.NoZOrder | SetWindowPosFlags.ShowWindow);
                Win32.SetWindowPos(_currentCtr.Handle, IntPtr.Zero, pRecScin.X, bar.Top + bar.Height, width, sqlH, SetWindowPosFlags.NoZOrder | SetWindowPosFlags.ShowWindow);
                _preViewHeights[key] = viewH;

                isDrag = false;
            };
            return(bar);
        }
示例#24
0
        public static void Clip(Processor processor)
        {
            Control.CheckForIllegalCrossThreadCalls = false;

            var clipForm = new Form
            {
                FormBorderStyle = FormBorderStyle.None,
                BackColor       = Color.Black,
                Opacity         = 0.25,
                ShowInTaskbar   = false,
                TopMost         = true
            };

            Label sizeLabel;

            clipForm.Controls.Add(sizeLabel = new Label
            {
                AutoSize  = false,
                Size      = new Size(90, 13),
                Left      = clipForm.Width - 75,
                Top       = clipForm.Height - 55,
                Anchor    = (AnchorStyles.Bottom | AnchorStyles.Right),
                ForeColor = Color.White
            });

            var screens = Screen.AllScreens.ToDictionary(s => s, s => GetScreenshot(s));

            List <Form> forms = new List <Form>();

            foreach (Screen screen in screens.Keys)
            {
                var screenForm = new Form
                {
                    Bounds          = screen.Bounds,
                    StartPosition   = FormStartPosition.Manual,
                    WindowState     = FormWindowState.Maximized,
                    FormBorderStyle = FormBorderStyle.None,
                    Opacity         = 0.01,
                    Cursor          = Cursors.Cross,
                    ShowInTaskbar   = false,
                    TopMost         = true
                };
                PictureBox screenImage;
                screenForm.Controls.Add(screenImage = new PictureBox
                {
                    Dock  = DockStyle.Fill,
                    Image = screens[screen]
                });
                screenForm.Show();
                screenForm.Focus();
                forms.Add(screenForm);

                new Thread(() =>
                {
                    Thread.Sleep(50);
                    screenForm.Opacity = 1.0;
                }).Start();

                screenImage.MouseDown += (s, e) =>
                {
                    var cursorColor = GetColor(screenImage, e.Location);
                    clipForm.BackColor  = cursorColor.ToArgb() > Color.Black.ToArgb() / 2 ? Color.Black : Color.White;
                    sizeLabel.ForeColor = cursorColor.ToArgb() > Color.Black.ToArgb() / 2 ? Color.White : Color.Black;
                };

                screenImage.MouseDown += (s, e) =>
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        _selectingArea    = true;
                        _startPoint       = screenImage.PointToScreen(e.Location);
                        clipForm.Location = _startPoint;
                        clipForm.Size     = new Size(1, 1);
                        clipForm.Show();
                    }
                };

                screenImage.MouseMove += (s, e) =>
                {
                    if (_selectingArea)
                    {
                        var newPoint = screenImage.PointToScreen(e.Location);
                        var point    = new Point(Math.Min(newPoint.X, _startPoint.X), Math.Min(newPoint.Y, _startPoint.Y));
                        var size     = new Size(Math.Max(newPoint.X, _startPoint.X) - point.X, Math.Max(newPoint.Y, _startPoint.Y) - point.Y);
                        if (clipForm.Location != point)
                        {
                            clipForm.Location = point;
                        }
                        clipForm.Size  = size;
                        sizeLabel.Text = size.Width + " x " + size.Height;
                    }
                };

                screenImage.MouseUp += (s, e) =>
                {
                    _selectingArea = false;
                    clipForm.Close();

                    forms.ForEach(f => f.Visible = false); // comment for debug

                    Bitmap bitmap;
                    if (screen.Bounds.Contains(clipForm.Bounds))
                    {
                        bitmap = GetClip(screenImage.Image, new Rectangle(screenForm.PointToClient(clipForm.Location), clipForm.Size));
                    }
                    else
                    {
                        bitmap = Collage(forms, clipForm.Location, clipForm.Size);
                    }

                    forms.ForEach(f => f.Close());

                    if (bitmap.Size.Width < 15 || bitmap.Size.Height < 15)
                    {
                        Terminate();                                                    //too small to see
                    }
                    processor.Process(bitmap);
                };

                clipForm.KeyDown    += (s, e) => Escape(e);
                screenForm.KeyDown  += (s, e) => Escape(e);
                screenImage.KeyDown += (s, e) => Escape(e);
            }
        }