Ejemplo n.º 1
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0312 && m.WParam.ToInt32() == SCREENSHOT_HOTKEY_ID && AllowScreenshots == true)
            {
                using (Bitmap bitmap = new Bitmap(screenWidth, screenHeight))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                        g.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

                    SaveImage("screenshot", bitmap);
                }
            }
            else if (m.Msg == 0x0312 && m.WParam.ToInt32() == SNIPPET_HOTKEY_ID && AllowScreenshots == true)
            {
                if ((Application.OpenForms["SnippingTool"] as SnippingTool) == null)
                {
                    var bitmap = SnippingTool.Snip();
                    if (bitmap != null)
                    {
                        SaveImage("snippet", new Bitmap(bitmap));
                    }
                }
            }
            base.WndProc(ref m);
        }
Ejemplo n.º 2
0
        public static Image Snip()
        {
            var rectangle = Screen.PrimaryScreen.Bounds;

            using (Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
            {
                using (Graphics graphics = Graphics.FromImage(bitmap))
                    graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

                using (var snipper = new SnippingTool(bitmap))
                {
                    if (snipper.ShowDialog() == DialogResult.OK)
                    {
                        return(snipper.Image);
                    }
                }
                return(null);
            }
        }