How To Make A Screen Capture Program In C#
All tutorials created in C# to be posted in here.
1 post
Page 1 of 1
hey guys
now i will give you a small guide to make a screen capture program in c-sharp first of all i want to say that this is not advanced program simply written ,
you need two buttons and button 1 will capture whole screen and button 2 will capture active window so now change the text and make the form small :lol:
this is my form
:o
now its time to code we are using two functions so now lets create the first function i will call it ActiveWindow so start with
now lets go ahead for the next function i named it WholeScreen so like what we did before just use
here is the full codes
hope this is really useful and sorry for my bad english
now i will give you a small guide to make a screen capture program in c-sharp first of all i want to say that this is not advanced program simply written ,
you need two buttons and button 1 will capture whole screen and button 2 will capture active window so now change the text and make the form small :lol:
this is my form
:o
now its time to code we are using two functions so now lets create the first function i will call it ActiveWindow so start with
Code: Select all
now we need to get the bounds of the screen so public void ActiveWindow()
{
Code: Select all
now we need to set the bitmap object to the size of the active window so rectangle.bounds = this.bounds;
Code: Select all
now the next step is taking a snap of the screen so using (Bitmap bmp = new Bitmap(bounds.Width, bounds.Height))
{
Code: Select all
now next is to save the screen snap as jpg in your desktop so using (Graphics gfx = Graphics.FromImage(bmp))
{
gfx.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
Code: Select all
now the ActiveWindow function is finishedString _path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ActiveWindow.jpg");
bmp.Save(_path);
}
}
now lets go ahead for the next function i named it WholeScreen so like what we did before just use
Code: Select all
now to capture the wholescreen its better to hide our application so usepublic void WholeScreen()
{
Code: Select all
and now lets the take the bounds of the screenthis.hide();
Code: Select all
now lets set the bitmap object to the size of the screen Rectangle bounds = Screen.PrimaryScreen.Bounds;
Code: Select all
after that lets snap your screen :lol: using (Bitmap bmp = new Bitmap(bounds.Width, bounds.Height))
{
p
Code: Select all
after that we need to save it to our desktop so using (Graphics gfx = Graphics.FromImage(bmp))
{
gfx.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
Code: Select all
now we will let the form to be visible String _path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "WholeScreen.jpg");
bmp.Save(_path);
}
Code: Select all
now functions are finished now lets make the functions work simply double click your button 1 and as i said before button 1 is for capturing whole screen so just writethis.show();
}
Code: Select all
and now for button to capture active window useWholeScreen();
Code: Select all
now your done making a screenshot program so now test it and your images will be in desktopActiveWindow();
here is the full codes
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Threading;
namespace Screenshot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void ActiveWindow()
{
Rectangle bounds = this.Bounds;
using (Bitmap bmp = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics gfx = Graphics.FromImage(bmp))
{
gfx.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
String _path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ActiveWindow.jpg");
bmp.Save(_path);
}
}
public void WholeScreen()
{
this.Hide();
Rectangle bounds = Screen.PrimaryScreen.Bounds;
using (Bitmap bmp = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics gfx = Graphics.FromImage(bmp))
{
gfx.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
String _path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "WholeScreen.jpg");
bmp.Save(_path);
}
this.Show();
}
private void button1_Click(object sender, EventArgs e)
{
WholeScreen();
}
private void button2_Click(object sender, EventArgs e)
{
ActiveWindow();
}
}
}
hope this is really useful and sorry for my bad english
Find my programs on Softpedia
1 post
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023