Пример #1
0
 // set the starting point of the Selection Box
 private void frmCapture_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button != MouseButtons.Left)
     {
         return;
     }
     // Get the screen we're capturing
     CaptureControl.CaptureScreen = Screen.FromPoint(Cursor.Position);
     CaptureControl.GetBackgroundImage();
     this.TransparencyKey = Color.White;
     _onClick             = true;
     // Get the click point relative to the screen we are capturing
     NativeClickPoint     = MousePosition.Substract(CaptureControl.CaptureScreen.Bounds.Location);
     SelectionPoint       = new Point(e.X, e.Y);
     pbSelection.Location = SelectionPoint;
 }
Пример #2
0
        private void frmCapture_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _onClick     = false;
                _donedrawing = true;
            }
            else if (e.Button == MouseButtons.Right)
            {
                clipboardToolStripMenuItem.Enabled = (Clipboard.ContainsImage() || Common.ImageFileInClipboard || Common.ImageUrlInClipboard);
            }

            if (_donedrawing)
            {
                _otherformopen = true;
                Hide();

                bool ValidRectangle = !(pbSelection.Size.Width == 0 && pbSelection.Size.Height == 0);
                if (_mouseMoved && ValidRectangle)
                {
                    if (pbSelection.Size.Width == 0 || pbSelection.Size.Height == 0)
                    {
                        string errorcase = (MousePosition.X == pbSelection.Location.X) ? "width" : "height";
                        string msg       = string.Format("Image {0} cannot be null", errorcase);
                        MessageBox.Show(null, msg, "upScreen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Common.KillOrWait(true);
                        return;
                    }

                    // Calculate the final selected area
                    // Location should be relative to the screen we are capturing
                    var s_FinalPoint = MousePosition.Substract(CaptureControl.CaptureScreen.Bounds.Location);

                    var s_LeftX   = s_FinalPoint.X > NativeClickPoint.X ? NativeClickPoint.X : s_FinalPoint.X;
                    var s_RightX  = s_FinalPoint.X <= NativeClickPoint.X ? NativeClickPoint.X : s_FinalPoint.X;
                    var s_TopY    = s_FinalPoint.Y > NativeClickPoint.Y ? NativeClickPoint.Y : s_FinalPoint.Y;
                    var s_BottomY = s_FinalPoint.Y <= NativeClickPoint.Y ? NativeClickPoint.Y : s_FinalPoint.Y;

                    var s_Width  = s_RightX - s_LeftX;
                    var s_Height = s_BottomY - s_TopY;

                    // Capture the selected area
                    Rectangle area = new Rectangle(s_LeftX, s_TopY, s_Width, s_Height);
                    CaptureControl.CaptureArea(area);
                }
                else
                {
                    try
                    {
                        // when single-clicking over the taskbar, capture it. Otherwise, capture the window from the cursor point
                        if (NativeClickPoint.Y > CaptureControl.CaptureScreen.WorkingArea.Height)
                        {
                            Rectangle taskbar = new Rectangle(0, CaptureControl.CaptureScreen.WorkingArea.Height, CaptureControl.CaptureScreen.Bounds.Width, CaptureControl.CaptureScreen.Bounds.Height - CaptureControl.CaptureScreen.WorkingArea.Height);
                            CaptureControl.CaptureArea(taskbar);
                        }
                        else
                        {
                            CaptureControl.CaptureWindow(Cursor.Position);
                        }
                    }
                    catch
                    {
                        Common.KillOrWait(true);
                    }
                }
            }
        }