private static Bitmap GetWindowBitmap(IntPtr handle) { WinApi.GetWindowRect(handle, out var rect); var bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1); var bounds2 = DesktopWindowManager.GetExtendedFrameBounds(handle); bounds = bounds2; var bitmap = new Bitmap(bounds.Width, bounds.Height); using (var graphics = Graphics.FromImage(bitmap)) { graphics.CopyFromScreen(bounds.Left, bounds.Top, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy); } return(bitmap); }
private void MainForm_Load(Object sender, EventArgs e) { this.UpgradeUserSettings(); //this.RestoreWindowPlacement(); //this.FormClosing += (s1, e1) => this.SaveWindowPlacement(); DesktopWindowManager.DisableTransitions(this.Handle); // no need to sleep after hide CheckRadioButton(this.groupBoxSource, Settings.Default.Source); CheckRadioButton(this.groupBoxTarget, Settings.Default.Target); this.linkLabelTargetDirectory.Text = String.IsNullOrEmpty(Settings.Default.TargetDirectory) ? Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) : Settings.Default.TargetDirectory; this.SetCheckBoxBitmask(this.groupBoxHotKey, Settings.Default.HotKeyModifiers); this.checkBoxOpenExplorerAfter.Checked = Settings.Default.OpenFileExplorer; for (var i = 0; i < 24; i++) { this.comboBoxHotKey.Items.Add(new VirtualKeyCodeItem(VirtualKeyCode.F1, i)); } for (var i = 0; i < 10; i++) { this.comboBoxHotKey.Items.Add(new VirtualKeyCodeItem(VirtualKeyCode.Key0, i)); } for (var i = 0; i < 26; i++) { this.comboBoxHotKey.Items.Add(new VirtualKeyCodeItem(VirtualKeyCode.KeyA, i)); } var virtualKeyCode = (VirtualKeyCode)Settings.Default.HotKeyVirtualKey; this.comboBoxHotKey.SelectedItem = this.comboBoxHotKey.Items.Cast <VirtualKeyCodeItem>().FirstOrDefault(i => i.VirtualKeyCode == virtualKeyCode) ?? this.comboBoxHotKey.Items[0]; var fileExtension = Settings.Default.Format; foreach (var fileFormat in this._fileFormats) { var index = this.comboBoxFileFormat.Items.Add(fileFormat); if (fileFormat.Extension.Equals(fileExtension)) { this.comboBoxFileFormat.SelectedIndex = index; } } if (this.comboBoxFileFormat.SelectedIndex < 0) { this.comboBoxFileFormat.SelectedIndex = 0; } this.checkBoxHideOnCapture.Checked = true; for (var i = 1; i < 10; i++) { this.comboBoxDelay.Items.Add(i); } this.comboBoxDelay.SelectedIndex = 4; this._systemWideHotKeys.KeyPressed += (s2, e2) => this.CaptureScreen(); void CheckRadioButton(GroupBox groupBox, Int32 tag) { var radioButton = groupBox.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Tag.ToString().Equals(tag.ToString())) as RadioButton ?? groupBox.Controls.OfType <RadioButton>().FirstOrDefault(); if (radioButton != null) { radioButton.Checked = true; } } }