window screenshot shenanigans
This commit is contained in:
parent
659f99e491
commit
124dea6fc2
1 changed files with 26 additions and 2 deletions
|
@ -1,4 +1,7 @@
|
||||||
using System.Windows.Forms;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace CreamInstaller.Components;
|
namespace CreamInstaller.Components;
|
||||||
|
|
||||||
|
@ -6,7 +9,12 @@ internal class CustomForm : Form
|
||||||
{
|
{
|
||||||
internal CustomForm() : base() => Icon = Properties.Resources.Icon;
|
internal CustomForm() : base() => Icon = Properties.Resources.Icon;
|
||||||
|
|
||||||
internal CustomForm(IWin32Window owner) : this() => Owner = (owner as Form) ?? ActiveForm;
|
internal CustomForm(IWin32Window owner) : this()
|
||||||
|
{
|
||||||
|
Owner = (owner as Form) ?? ActiveForm;
|
||||||
|
KeyPreview = true;
|
||||||
|
KeyPress += OnKeyPress;
|
||||||
|
}
|
||||||
|
|
||||||
protected override CreateParams CreateParams // Double buffering for all controls
|
protected override CreateParams CreateParams // Double buffering for all controls
|
||||||
{
|
{
|
||||||
|
@ -24,4 +32,20 @@ internal class CustomForm : Form
|
||||||
int Y = fromForm.Location.Y + fromForm.Size.Height / 2 - Size.Height / 2;
|
int Y = fromForm.Location.Y + fromForm.Size.Height / 2 - Size.Height / 2;
|
||||||
Location = new(X, Y);
|
Location = new(X, Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnKeyPress(object s, KeyPressEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.KeyChar != 'S') return; // Shift + S
|
||||||
|
UpdateBounds();
|
||||||
|
Rectangle bounds = Bounds;
|
||||||
|
using Bitmap bitmap = new(Size.Width - 14, Size.Height - 7);
|
||||||
|
using Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
ImageCodecInfo jpeg = ImageCodecInfo.GetImageEncoders()[1];
|
||||||
|
using EncoderParameters encoding = new(1);
|
||||||
|
encoding.Param[0] = new(Encoder.Quality, 100L);
|
||||||
|
graphics.CopyFromScreen(new(bounds.Left + 7, bounds.Top), Point.Empty, new(Size.Width - 14, Size.Height - 7));
|
||||||
|
Clipboard.SetImage(bitmap);
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue