/// <summary> /// Register or unregister a hotkey /// </summary> private void RegisterHotkey(MOBZystems.Hotkey hotkey, bool register) { if (register) { if (!hotkey.IsRegistered) { hotkey.Register(this); } } else { if (hotkey.IsRegistered) { hotkey.Unregister(); } } }
/// <summary> /// Constructor /// </summary> public SeeThrougWindowsForm() { this.loading = true; InitializeComponent(); Version version = new Version(Application.ProductVersion); this.helpLink.Text = this.helpLink.Text .Replace("#V#", string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.Build)) .Replace("#3264#", (IntPtr.Size * 8).ToString()); // Use same icon for notify icon as for this form this.notifyIcon.Icon = this.Icon; // Read our settings from the registry: RegistryKey root = Registry.CurrentUser.CreateSubKey(REGROOT); // First transparency: this.semiTransparentValue = short.Parse((string)root.GetValue("Transparency", DEFAULT_SEMITRANSPARENT.ToString())); if (this.semiTransparentValue < this.transparencyTrackBar.Minimum) { this.semiTransparentValue = (short)this.transparencyTrackBar.Minimum; } if (this.semiTransparentValue > this.transparencyTrackBar.Maximum) { this.semiTransparentValue = (short)this.transparencyTrackBar.Maximum; } // Click-through-ness: this.clickThroughCheckBox.Checked = BoolFromString((string)root.GetValue("ClickThrough", "0")); this.topMostCheckBox.Checked = BoolFromString((string)root.GetValue("TopMost", "1")); // Then the hot key: string hotkeyString = (string)root.GetValue("Hotkey", "Z"); bool shiftKey = BoolFromString((string)root.GetValue("Shift", "1")); bool controlKey = BoolFromString((string)root.GetValue("Control", "1")); bool altKey = BoolFromString((string)root.GetValue("Alt", "0")); bool windowsKey = BoolFromString((string)root.GetValue("Windows", "0")); this.sendToMonitorEnabledCheckBox.Checked = BoolFromString((string)root.GetValue("EnableLeftRight", "1")); this.minMaxEnabledCheckBox.Checked = BoolFromString((string)root.GetValue("EnableUpDown", "1")); this.enableChangeTransparencyCheckbox.Checked = BoolFromString((string)root.GetValue("EnablePageUpDown", "1")); // Create a hot key with the settings: this.userHotkey = new MOBZystems.Hotkey(MOBZystems.Hotkey.KeyCodeFromString(hotkeyString), shiftKey, controlKey, altKey, windowsKey); // Catch the 'Pressed' event this.userHotkey.Pressed += new HandledEventHandler(UserHotkey_Pressed); this.userHotkey.Register(this); this.minimizeHotkey.Pressed += new HandledEventHandler(MinimizeHotkey_Pressed); if (this.minMaxEnabledCheckBox.Checked) { this.minimizeHotkey.Register(this); } this.maximizeHotkey.Pressed += new HandledEventHandler(MaximizeHotkey_Pressed); if (this.minMaxEnabledCheckBox.Checked) { this.maximizeHotkey.Register(this); } this.previousScreenHotkey.Pressed += new HandledEventHandler(PreviousScreenHotkey_Pressed); if (this.sendToMonitorEnabledCheckBox.Checked) { this.previousScreenHotkey.Register(this); } this.nextScreenHotkey.Pressed += new HandledEventHandler(NextScreenHotkey_Pressed); if (this.sendToMonitorEnabledCheckBox.Checked) { this.nextScreenHotkey.Register(this); } this.moreTransparentHotkey.Pressed += new HandledEventHandler(MoreTransparentHotkey_Pressed); if (this.enableChangeTransparencyCheckbox.Checked) { this.moreTransparentHotkey.Register(this); } this.lessTransparentHotkey.Pressed += new HandledEventHandler(LessTransparentHotkey_Pressed); if (this.enableChangeTransparencyCheckbox.Checked) { this.lessTransparentHotkey.Register(this); } // Set up our form: for (Keys k = Keys.A; k <= Keys.Z; k++) { AddKeyToComboBox(k); } for (Keys k = Keys.F1; k <= Keys.F24; k++) { AddKeyToComboBox(k); } //AddKeyToComboBox(Keys.Up); //AddKeyToComboBox(Keys.Down); //AddKeyToComboBox(Keys.Left); //AddKeyToComboBox(Keys.Right); //AddKeyToComboBox(Keys.Home); //AddKeyToComboBox(Keys.End); //AddKeyToComboBox(Keys.PageDown); //AddKeyToComboBox(Keys.PageUp); // Update the form now controls this.shiftCheckBox.Checked = this.userHotkey.Shift; this.controlCheckBox.Checked = this.userHotkey.Control; this.altCheckBox.Checked = this.userHotkey.Alt; this.windowsCheckBox.Checked = this.userHotkey.Windows; this.transparencyTrackBar.Value = this.semiTransparentValue; // Done loading this.loading = false; }