Advertisement
Guest User

Knx

a guest
Apr 21st, 2009
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Imaging;
  4. using System.Windows.Forms;
  5. using System.IO;
  6.  
  7. namespace ScreenSnap
  8. {
  9.     public partial class Main : Form
  10.     {
  11.         #region METHODS
  12.         #region CONSTRUCTORS
  13.         public Main()
  14.         {
  15.             InitializeComponent();
  16.  
  17.             TextBoxFolder.Text = Application.StartupPath;
  18.         }
  19.         #endregion
  20.  
  21.         public Image ImageCapture(int Width, int Height, int X, int Y)
  22.         {
  23.             this.Opacity = 0;
  24.             Rectangle ScreenBounds = new Rectangle(X, Y, Width, Height);
  25.             Bitmap Screenshot = new Bitmap(ScreenBounds.Width, ScreenBounds.Height, PixelFormat.Format32bppArgb);
  26.             Graphics ScreenGraph = Graphics.FromImage(Screenshot);
  27.             ScreenGraph.CopyFromScreen(ScreenBounds.X, ScreenBounds.Y, 0, 0, ScreenBounds.Size, CopyPixelOperation.SourceCopy);
  28.             Image Img = (Image)Screenshot;
  29.             this.Opacity = 100;
  30.             return Img;
  31.         }
  32.  
  33.         public void ImageSave(Image Img)
  34.         {
  35.             if (Directory.Exists(TextBoxFolder.Text))
  36.             {
  37.                 string Name = TextBoxFolder.Text + @"\" + TextBoxFileName.Text + (DateTime.Now.ToFileTime()) + ".jpg";
  38.                 Img.Save(Name, ImageFormat.Jpeg);
  39.             }
  40.             else
  41.                 MessageBox.Show("Invalid folder", "Error");
  42.         }
  43.         #endregion
  44.  
  45.         #region EVENTS
  46.         private void ButtonScreenshot_Click(object sender, EventArgs e)
  47.         {
  48.             try
  49.             {
  50.                 ImageSave(ImageCapture(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
  51.                     Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y));
  52.             }
  53.             catch
  54.             {
  55.                 MessageBox.Show("Unknow error!", "Error");
  56.             }
  57.         }
  58.         private void ButtonScreenshotWindow_Click(object sender, EventArgs e)
  59.         {
  60.             try
  61.             {
  62.                 /**
  63.                 ImageCapture(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
  64.                     Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y);
  65.                 ImageSave();
  66.                 /**/
  67.             }
  68.             catch
  69.             {
  70.                 MessageBox.Show("Unknow error!", "Error");
  71.             }
  72.         }
  73.  
  74.         private void ButtonFolderBrowse_Click(object sender, EventArgs e)
  75.         {
  76.             if (FolderBrowserDialogSave.ShowDialog() == DialogResult.OK)
  77.                 TextBoxFolder.Text = FolderBrowserDialogSave.SelectedPath;
  78.         }
  79.         #endregion
  80.     }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement