Windows Forms: Capture Screenshot & Record your computer screen in C#

How to Capture Screenshot & Record your computer screen in C#

Step 1Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "CaptureScreenshot" and then click OK

capture screenshot c#Step 2: Design your form as below

take screenshot in c#

Step 3: Add code to handle your form as below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CaptureScreenshot
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCapture_Click(object sender, EventArgs e)
        {
            Bitmap bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics g = Graphics.FromImage(bm);
            g.CopyFromScreen(0, 0, 0, 0, bm.Size);
            pictureBox.Image = bm;
        }

        //Capture screenshot
        void Capture()
        {
            while (true)
            {
                Bitmap bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                Graphics g = Graphics.FromImage(bm);
                g.CopyFromScreen(0, 0, 0, 0, bm.Size);
                pictureBox.Image = bm;
                Thread.Sleep(1000);
            }
        }

        private void btnRecord_Click(object sender, EventArgs e)
        {
            //Start new thread to record your screen
            Thread t = new Thread(Capture);
            t.Start();
        }
    }
}

VIDEO TUTORIALS