1

I made this simple little application which goes in the notification area (the little arrow on the taskbar which holds a few applications that run in the background).

I have a button made where I can minimize it using:

this.WindowState = FormWindowState.Minimized;

and I can put the WindowState back to normal mode with:

this.WindowState = FormWindowState.Normal;

This all works fine however when I try to click outside the application to minimize it, instead of pressing the button for it, it doesn't wanna go back to the normal state, even if I use the statement mentioned before.

Is there any setting I can use to toggle this behaviour, or do I need to change something inside the script and if so, what?

I've tried searching through the different settings on both the NotifyIcon and the ContextMenuStrip but couldn't find anything relevant but I might have also just missed it.

I've also tried to search through stackoverflow, but I'm not really sure what to search for, since nothing really popped up when trying to search for almost the same thing as the title on this thread.

Current Code:

        private void button1_Click(object sender, EventArgs e)
        {
            File.WriteAllText("count.txt", count.ToString()); // Ignore this
            this.WindowState = FormWindowState.Minimized;
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void showToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • How do you handle click outside of the application? – Reza Aghaei Jan 09 '23 at 21:50
  • @RezaAghaei It's not really something I handle, I'm not really sure how the program sees the click outside the window since I think it's just another way of minimizing it, since thats basically what it does if you pull up a non maximized window and then click outside of that window. However I might be wrong on that and it might see it like a different type of minimization, but there aren't really any more types of WindowStates, except for Minimized, Normal and Maximized. – Paul From Walmart Jan 09 '23 at 21:55
  • When clicking outside the window, it just deactivates. I'm not sure what exactly you mean here. Are you talking about aero shake (to minimize other windows)? A step by step reproduction + a screenshot may help. – Reza Aghaei Jan 09 '23 at 22:18
  • Oh wait, you know what? I just figured out the issue. It wasn't that it was minimizing the window when clicking out or anything related to aero shaking, it was prioritizing the window I was clicking onto and just making the form go under that window, so it was still on the WindowState Normal but just hidden under another window. – Paul From Walmart Jan 09 '23 at 22:24

1 Answers1

0

Figured out that the issue was not about it minimizing the form, however it was prioritizing the window I was clicking on. To fix this and change it to the top I used

this.TopMost = true

Which worked perfectly.