Click here to Skip to main content
15,886,802 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code

C#
// The size of the browser window when we want to take the screenshot (and the size of the resulting bitmap)
  Bitmap bitmap = new Bitmap(MainPicturebox.Width, MainPicturebox.Height);
  Rectangle bitmapRect = new Rectangle(0, 0, MainPicturebox.Width, MainPicturebox.Height);
  // This is a method of the panel control, and the most important part
  panel1.DrawToBitmap(bitmap, bitmapRect);

  // Generate a thumbnail of the screenshot (optional)
  System.Drawing.Image origImage = bitmap;
  System.Drawing.Image origThumbnail = new Bitmap(120, 90, origImage.PixelFormat);

  Graphics oGraphic = Graphics.FromImage(origThumbnail);
  oGraphic.CompositingQuality = CompositingQuality.HighQuality;
  oGraphic.SmoothingMode = SmoothingMode.HighQuality;
  oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
  Rectangle oRectangle = new Rectangle(0, 0, 120, 90);
  oGraphic.DrawImage(origImage, oRectangle);

  // Save the file in PNG format
  origImage.Save("Screenshot.png", ImageFormat.Png);
  origImage.Dispose();


Right now it takes a screen shot of the panel including the scroll bar which i don't wont in it, I want it to take a screen shot of all that is in the panel for example, i might have a autosized picuebox which autosized beond the bounries of the panel, whcih will show the scroll bars, i want it to take a screen shot of everytthing, all the stuff beond the broundies and etc etc, but i don't want to the scroll bars to be seen wither, can some one please help me achive this?
Posted

1 solution

First of all, your use of PictureBox is totally pointless. This class itself is totally redundant, it is used only for simplification of some basic things like showing a static picture. Its use for anything dynamic, interactive or animated only makes it a hassle. In your case, you only need to use the bitmap.

Now, you don't even try to capture anything at all.

You can use the method System.Drawing.Graphics.CopyFromScreen:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.copyfromscreen.aspx[^].

Suppose you want to copy a panel. Take a position of the left top corner of your panel in screen coordinates. This is how:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen.aspx[^].

Use this method: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.copyfromscreen.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900