0% found this document useful (0 votes)
2 views2 pages

using System; capcher2

This C# Windows Forms application captures screenshots based on user-defined configurations. It reads settings such as folder path, image dimensions, delay, and file name from a 'config.txt' file. When a button is clicked, it captures the screen after the specified delay and saves the image in the designated folder with a timestamp in the filename.

Uploaded by

huysovai080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

using System; capcher2

This C# Windows Forms application captures screenshots based on user-defined configurations. It reads settings such as folder path, image dimensions, delay, and file name from a 'config.txt' file. When a button is clicked, it captures the screen after the specified delay and saves the image in the designated folder with a timestamp in the filename.

Uploaded by

huysovai080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.IO;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private string folderPath;
private int width, height, delay;
private string fileName;

public Form1()
{
InitializeComponent();
LoadConfig(); // Gọi hàm đọc cấu hình khi mở app
}

private void LoadConfig()


{
try
{
string[] lines = File.ReadAllLines("config.txt");
foreach (string line in lines)
{
string[] parts = line.Split('=');
if (parts.Length == 2)
{
string key = parts[0].Trim();
string value = parts[1].Trim();

if (key == "FolderPath") folderPath = value;


else if (key == "Width") width = int.Parse(value);
else if (key == "Height") height = int.Parse(value);
else if (key == "Delay") delay = int.Parse(value);
else if (key == "FileName") fileName = value;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Lỗi đọc file cấu hình: " + ex.Message);
}
}

private void CaptureScreenshot()


{
Thread.Sleep(delay * 1000); // Chờ theo thời gian cấu hình

Bitmap bitmap = new Bitmap(width, height);


Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

string filePath = Path.Combine(folderPath,


$"{fileName}_{DateTime.Now:yyyyMMdd_HHmmss}.png");
bitmap.Save(filePath);
MessageBox.Show($"Ảnh đã lưu: {filePath}", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void button1_Click(object sender, EventArgs e)


{
CaptureScreenshot();
}
}
}

You might also like