private void SnippingToolWindow_Load(object sender, EventArgs e) { TopMost = true; ImageDimensions = new Rectangle(0, 0, 1, 1); foreach (Screen S in Screen.AllScreens) { if (S.Bounds.X < ImageDimensions.X) { ImageDimensions.X = S.Bounds.X; } if (S.Bounds.Y < ImageDimensions.Y) { ImageDimensions.Y = S.Bounds.Y; } if (S.Bounds.X + S.Bounds.Width > ImageDimensions.Width) { ImageDimensions.Width = S.Bounds.X + S.Bounds.Width; } if (S.Bounds.Y + S.Bounds.Height > ImageDimensions.Height) { ImageDimensions.Height = S.Bounds.Y + S.Bounds.Height; } } ImageDimensions.Width -= ImageDimensions.X; ImageDimensions.Height -= ImageDimensions.Y; fullScreenshot = new Bitmap(ImageDimensions.Width, ImageDimensions.Height, PixelFormat.Format32bppRgb); using (Graphics graphics = Graphics.FromImage(fullScreenshot)) graphics.CopyFromScreen(ImageDimensions.X, ImageDimensions.Y, 0, 0, new Size(ImageDimensions.Width, ImageDimensions.Height), CopyPixelOperation.SourceCopy); Location = new Point(ImageDimensions.X, ImageDimensions.Y); Size = new Size(ImageDimensions.Width, ImageDimensions.Height); Bitmap TransparentScreenshot = (Bitmap)fullScreenshot.Clone(); TransparentScreenshot.MakeTransparent(Color.Beige); pBox.Image = TransparentScreenshot; DLLImports.SetForegroundWindow(this.Handle); }
public void Minimize() => DLLImports.ShowWindow(this.Handle, 2);
public void AddScreenShotSnippingToolStyle() { if (snippingWindowActive) { return; } lock (snipper) { try { snippingWindowActive = true; System.Media.SystemSounds.Exclamation.Play(); snipper.ShowDialog(); if (snipper.output != null) { Task.Run(() => this.InvokeIfRequired(() => { try { images.Add(new Screenshot(snipper.output, GetScreenshotName())); imagesIndex = images.Count - 1; UpdateUI(); BSave_Click(null, EventArgs.Empty); Point mouseDownPoint = snipper.pMouseDown; Rectangle imageDimensions = snipper.ImageDimensions; snipper.InvokeIfRequired(() => Location = new Point(mouseDownPoint.X + imageDimensions.X - 8 - pBox.Location.X, mouseDownPoint.Y - 32 - pBox.Location.Y)); WindowState = FormWindowState.Normal; DLLImports.SetForegroundWindow(Handle); SetOriginalSize(); // Ausgleichen des blankParts int imgWidth = pBox.Image.Width; int imgHeight = pBox.Image.Height; int boxWidth = pBox.Size.Width; int boxHeight = pBox.Size.Height; float X = 0; float Y = 0; if (imgWidth / imgHeight > boxWidth / boxHeight) { float scale = boxWidth / (float)imgWidth; float blankPart = (boxHeight - scale * imgHeight) / 2; Y = blankPart; } else { float scale = boxHeight / (float)imgHeight; float blankPart = (boxWidth - scale * imgWidth) / 2; X = blankPart; } Location = new Point(Location.X - (int)X, Location.Y - (int)Y); snipper.CleanUp(); } catch (Exception e) { if (MessageBox.Show("Oopsie woopsie, it seems like I cant make that screenshot!\nDo you want to see the error message in detail?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { MessageBox.Show(e.Message + "\n\n" + e.InnerException + "\n\n" + e.StackTrace); } } snippingWindowActive = false; })); } else { snippingWindowActive = false; } } catch (Exception e) { if (MessageBox.Show("Oopsie woopsie, it seems like I cant make that screenshot!\nDo you want to see the error message in detail?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { MessageBox.Show(e.Message + "\n\n" + e.InnerException + "\n\n" + e.StackTrace); } } } }