0

I've been looking around and cant seem to find any of the help I need for my program I need it so when I click a specific button(F9) It hides the program from taskbar. After its hidden from taskbar I need to be able to click a button(F10) to make it Show in task bar again. Currently when I run it F9 Hides it but F10 wont show it

        private void Menu_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F9)
            {
                SecHiden.PerformClick();
            }
            if (e.KeyCode == Keys.F10)
            {
                SecShow.PerformClick();
            }
        }

        private void SecHiden_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            this.ShowInTaskbar = false;
        }

        private void SecShow_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
            this.ShowInTaskbar = true;
        }   
    }
}

EDIT: i've figured out the error just need help fixing it I have to be tabbed into the program for the Keybinds to work is there a way to fix this? I would like to able to use the keybinds when im on Any specift tab(F10 Wouldnt show the tab because I wasnt tabbed onto the program to make the keybind work)

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Xern
  • 1
  • 2
  • Can you put a breakpoint in SecShow_Click and check if it is being hit in the debugger? – Zee Mar 12 '22 at 18:29
  • Does the application has the focus when you press the `F10` key? – Progman Mar 12 '22 at 18:35
  • @Zee. How would I do that sorry i'm kind of new to coding? – Xern Mar 12 '22 at 19:24
  • @Xern Check this post https://learn.microsoft.com/en-us/visualstudio/debugger/using-breakpoints?view=vs-2022 – Zee Mar 12 '22 at 19:25
  • @Zee Okay Thank you. When I run the code after adding the breakpoint when i Push F10 it just freezes the program – Xern Mar 12 '22 at 20:14
  • 1
    F10 is a system hotkey for activating the menu bar. Choose a different hotkey. – Raymond Chen Mar 12 '22 at 23:19
  • What happens if you physically click the button? By the way `if (e.KeyCode == Keys.F9 && e.KeyCode == Keys.F9)` seems repetitive – Charlieface Mar 13 '22 at 00:47
  • Okay this is what ive found out now just need help with the solution The keybinds(F10, F9) Only work when im tabbed into the main form – Xern Mar 13 '22 at 02:24
  • This way, your app won't receive the key messages if it is not the active app. You need a different approach for this. Either by registering global [hot keys](https://stackoverflow.com/a/15413314/14171304) or [global keyboard hook](https://stackoverflow.com/questions/604410/global-keyboard-capture-in-c-sharp-application). – dr.null Mar 13 '22 at 03:28
  • @dr.null Do you know how I would rewrite this into my code? – Xern Mar 13 '22 at 05:59
  • Yes, study the provided examples and try to apply what you understand. [Here's](https://stackoverflow.com/questions/65853407/winforms-global-hotkey-typing-interference) another one to study. Using a Timer + `GetAsyncKeyState` function. Read, google for more info, and code... – dr.null Mar 13 '22 at 06:20
  • If you want this to be a global hotkey, then definitely choose something different from F10, since F10 is likely to be used by other programs for their own purposes (like accessing the menu bar!) – Raymond Chen Mar 13 '22 at 14:13

0 Answers0