Example #1
0
        public void screenCapture(bool showCursor)
        {
            Point curPos  = new Point(Cursor.Position.X, Cursor.Position.Y);
            Size  curSize = new Size();

            curSize.Height = Cursor.Current.Size.Height;
            curSize.Width  = Cursor.Current.Size.Width;

            var path = Application.StartupPath + "\\images\\";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path = path + DateTime.Now.Ticks.ToString() + ".jpg";

            ScreenPath = path;

            //if (!ScreenShot.saveToClipboard)
            //{

            //    saveFileDialog1.DefaultExt = "bmp";
            //    saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|tiff files (*.tiff)|*.tiff|png files (*.png)|*.png";
            //    saveFileDialog1.Title = "Save screenshot to...";
            //    saveFileDialog1.ShowDialog();
            //    ScreenPath = saveFileDialog1.FileName;

            //}



            if (ScreenPath != "" || ScreenShot.saveToClipboard)
            {
                //Conceal this form while the screen capture takes place
                this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                this.TopMost     = false;

                //Allow 250 milliseconds for the screen to repaint itself (we don't want to include this form in the capture)
                System.Threading.Thread.Sleep(250);

                Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
                string    fi     = "";

                if (ScreenPath != "")
                {
                    fi = new FileInfo(ScreenPath).Extension;
                }

                ScreenShot.CaptureImage(showCursor, curSize, curPos, Point.Empty, Point.Empty, bounds, ScreenPath, fi);

                //The screen has been captured and saved to a file so bring this form back into the foreground
                this.WindowState = System.Windows.Forms.FormWindowState.Normal;
                this.TopMost     = true;

                if (ScreenShot.saveToClipboard)
                {
                    if (checkBoxShowMessageboxAfterCapture.Checked)
                    {
                        MessageBox.Show("Screen saved to clipboard", "TeboScreen", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    if (checkBoxShowMessageboxAfterCapture.Checked)
                    {
                        MessageBox.Show("Screen saved to file", "TeboScreen", MessageBoxButtons.OK);
                    }
                }
            }
        }