Я хочу сделать скриншот области экрана на С#, но у меня не получается.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EquaScreenshot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool isLMB = false;
private Point point1;
private Point point2;
private int width;
private int height;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isLMB = true;
point1 = new Point(Cursor.Position.X, Cursor.Position.Y);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isLMB)
{
point2 = new Point(Cursor.Position.X, Cursor.Position.Y);
width = point2.X - point1.X;
height = point2.Y - point1.Y;
pictureBox1.Size = new Size(width, height);
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
Cursor = Cursors.Default;
isLMB = false;
pictureBox1.BackColor = Color.Blue;
pictureBox1.Location = point1;
this.Opacity = .85;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.menuStrip1.Visible = true;
}
private void makeToolStripMenuItem_Click(object sender, EventArgs e)
{
Cursor = Cursors.Cross;
this.WindowState = FormWindowState.Maximized;
this.Opacity = .5;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.menuStrip1.Visible = false;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Width = 10000;
pictureBox1.Height = 10000;
pictureBox1.BackColor = Color.White;
}
private void Screenshot(string CapturedFilePath)
{
Bitmap bitmap = new Bitmap
(width, height);
Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
graphics.CopyFromScreen(0, 0, 0,0, bitmap.Size);
bitmap.Save(CapturedFilePath, ImageFormat.Jpeg);
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "JPEG(*.JPEG)|*.jpeg";
saveFileDialog1.FileName = DateTime.Now.ToString("s_m_dd_MM_yyyy");
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
this.WindowState = FormWindowState.Minimized;
System.Threading.Thread.Sleep(500);
Screenshot(saveFileDialog1.FileName);
}
}
}
}
Вот что у меня получилось(я знаю что код может быть не самым качественным, но это мое 2 приложение на С#), но он делает скрин только левого верхнего угла.