Graphics.CopyFromScreen
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing.Drawing2D;
public class Form1 : Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button cmdCapture;
private System.Windows.Forms.PictureBox pictureBox1;
public Form1() {
InitializeComponent();
}
private void cmdCapture_Click(object sender, EventArgs e)
{
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
g.Dispose();
pictureBox1.Image = bmp;
pictureBox1.Size = bmp.Size;
}
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.cmdCapture = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(8, 8);
this.panel1.Size = new System.Drawing.Size(270, 233);
this.cmdCapture.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cmdCapture.Location = new System.Drawing.Point(169, 249);
this.cmdCapture.Size = new System.Drawing.Size(110, 30);
this.cmdCapture.Text = "Capture Screen";
this.cmdCapture.UseVisualStyleBackColor = true;
this.cmdCapture.Click += new System.EventHandler(this.cmdCapture_Click);
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabStop = false;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(290, 288);
this.Controls.Add(this.cmdCapture);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Text = "Screen Capture";
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Related examples in the same category
1. | Graphics.Clear | | |
2. | Graphics.DashCap | | |
3. | Graphics.Dispose() | | |
4. | Graphics.DpiX | | |
5. | Graphics.DpiY | | |
6. | Graphics.DrawArc | | |
7. | Graphics.DrawBeziers | | |
8. | Graphics.DrawEllipse | | |
9. | Graphics.DrawIcon(Icon icon, int x, int y) | | |
10. | Graphics.DrawImage(Image i, int x, int y); | | |
11. | Graphics.DrawImage(Image img, int x, int y, int width, int height) | | |
12. | Graphics.DrawImage(im, rec, recPart, GraphicsUnit.Pixel) | | |
13. | Graphics.DrawImage(Image, Points[]) | | |
14. | Graphics.DrawLine(Pen p, int x0,int y0, int x1, int y1) | | |
15. | Graphics.DrawLine(Pen,Point point1, Point point2) | | |
16. | Graphics.DrawLines(Pen pen, Point[] points) | | |
17. | Graphics.DrawPie | | |
18. | Graphics.DrawRectangle | | |
19. | Graphics.DrawRectangles | | |
20. | Graphics.DrawString | | |
21. | Graphics.EnumerateMetafileProc | | |
22. | Graphics.FillClosedCurve | | |
23. | Graphics.FillEllipse | | |
24. | Graphics.FillEllipse(Brush brush,int x, int y,int width,int height) | | |
25. | Graphics.FillPath(Brushes.AliceBlue, myPath); | | |
26. | Graphics.FillPolygon | | |
27. | Graphics.FillRectangle | | |
28. | Graphics.FillRectangles | | |
29. | Graphics.FillRegion | | |
30. | Graphics.FromHwnd() | | |
31. | Graphics.FromImage | | |
32. | Graphics.InterpolationMode | | |
33. | Graphics.MeasureString | | |
34. | Graphics.PageScale | | |
35. | Graphics.PageUnit | | |
36. | Graphics.PixelOffsetMode | | |
37. | Graphics.ReleaseHdc | | |
38. | Graphics.RotateTransform | | |
39. | Graphics.ScaleTransform | | |
40. | Graphics.SetClip | | |
41. | Graphics.SetClip(path, (CombineMode)miCombineMode.Index) | | |
42. | Graphics.SmoothingMode | | |
43. | Graphics.TextRenderingHint | | |
44. | Graphics.Transform | | |
45. | Graphics.TranslateClip | | |
46. | Graphics.TranslateTransform | | |
47. | Graphics.VisibleClipBounds | | |