Upload files
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
54
MainForm.cs
Normal file
54
MainForm.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ScreenCaptureApp
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnCapture_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Hide();
|
||||
using (var captureForm = new ScreenCaptureForm())
|
||||
{
|
||||
if (captureForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
SaveImage(captureForm.CapturedImage);
|
||||
}
|
||||
}
|
||||
this.Show();
|
||||
}
|
||||
|
||||
private void SaveImage(Image image)
|
||||
{
|
||||
using (SaveFileDialog sfd = new SaveFileDialog())
|
||||
{
|
||||
sfd.Filter = "PNG Image|*.png|JPEG Image|*.jpg|Bitmap Image|*.bmp";
|
||||
sfd.Title = "Save Screenshot";
|
||||
sfd.FileName = "screenshot.png";
|
||||
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
image.Save(sfd.FileName, GetImageFormat(sfd.FileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private System.Drawing.Imaging.ImageFormat GetImageFormat(string fileName)
|
||||
{
|
||||
string ext = System.IO.Path.GetExtension(fileName).ToLower();
|
||||
switch (ext)
|
||||
{
|
||||
case ".jpg": return System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||
case ".jpeg": return System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||
case ".bmp": return System.Drawing.Imaging.ImageFormat.Bmp;
|
||||
default: return System.Drawing.Imaging.ImageFormat.Png;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user