Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. NotifyIcon does not respond

NotifyIcon does not respond

Scheduled Pinned Locked Moved C#
help
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D danielhasdibs

    Ok, hopefully, this will be an easier problem to solve. I have a program that has a NotifyIcon control. When the user completes the MainFrame form, the window minimizes and then hides. I want to be able to double-click the notifyicon to make the window reappear. I also want to be able to right-click the n-icon and have my context menu strip show. Now this works perfectly well when the window (MainFrame) is minimized, but once the user completes the MF form and the window hides, the n-icon does not respond. Here's my code: private void MainFrm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) Hide(); } ... private void TB_Icon_DoubleClick(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } ... private void TB_Icon_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContMenuStrip.Show(); } } ... private void ContMenuStrip_Click(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running. Nothing happens when I double-click or right-click on the notifyicon. Thanks for the help.

    D Offline
    D Offline
    DaveyM69
    wrote on last edited by
    #2

    The double click event for the notify icon should be MouseDoubleClick. The TB_Icon_MouseUp method should not be needed - assign ContMenuStrip to TB_Icon's ContextMenuStrip property.

    Dave

    D 1 Reply Last reply
    0
    • D DaveyM69

      The double click event for the notify icon should be MouseDoubleClick. The TB_Icon_MouseUp method should not be needed - assign ContMenuStrip to TB_Icon's ContextMenuStrip property.

      Dave

      D Offline
      D Offline
      danielhasdibs
      wrote on last edited by
      #3

      I changed it to MouseDoubleClick and the ContMenuStrip is already assigned to the ContextMenuStrip property of TB_Icon. Still, the icon does not respond.

      D 1 Reply Last reply
      0
      • D danielhasdibs

        I changed it to MouseDoubleClick and the ContMenuStrip is already assigned to the ContextMenuStrip property of TB_Icon. Still, the icon does not respond.

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #4

        This is working for me. (Added button[btnOK], notifyIcon[TB_Icon], contextMenuStrip[ContMenuStrip] and a toolStripMenuItem to ContMenuStrip with TB_Icon's ContextMenuStrip property set to ContMenuStrip)

        public partial class MainFrm : Form
        {
        public MainFrm()
        {
        InitializeComponent();
        btnOK.Click += new EventHandler(btnOK_Click); Resize += new EventHandler(MainFrm_Resize);
        TB_Icon.MouseDoubleClick += new MouseEventHandler(TB_Icon_MouseDoubleClick);
        ContMenuStrip.Click += new EventHandler(ContMenuStrip_Click);
        }

            void btnOK\_Click(object sender, EventArgs e)
            {
                WindowState = FormWindowState.Minimized;
            }
        
            void MainFrm\_Resize(object sender, EventArgs e)
            {
                if (WindowState == FormWindowState.Minimized)
                    Hide();
            }
        
            void TB\_Icon\_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                Show();
                WindowState = FormWindowState.Normal;
            }
        
            void ContMenuStrip\_Click(object sender, EventArgs e)
            {
                Show();
                WindowState = FormWindowState.Normal;
            }
        }
        

        Dave

        1 Reply Last reply
        0
        • D danielhasdibs

          Ok, hopefully, this will be an easier problem to solve. I have a program that has a NotifyIcon control. When the user completes the MainFrame form, the window minimizes and then hides. I want to be able to double-click the notifyicon to make the window reappear. I also want to be able to right-click the n-icon and have my context menu strip show. Now this works perfectly well when the window (MainFrame) is minimized, but once the user completes the MF form and the window hides, the n-icon does not respond. Here's my code: private void MainFrm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) Hide(); } ... private void TB_Icon_DoubleClick(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } ... private void TB_Icon_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContMenuStrip.Show(); } } ... private void ContMenuStrip_Click(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running. Nothing happens when I double-click or right-click on the notifyicon. Thanks for the help.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #5

          Hi, why do you hide the main form when it gets minimized? when it gets minimized it is no longer visible on the desktop. I am afraid hiding it explicitly makes it not responding on anything anymore until you somehow make it visible again. if you want to remove it from the task bar, use the Form.ShowInTaskbar Property :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


          1 Reply Last reply
          0
          • D danielhasdibs

            Ok, hopefully, this will be an easier problem to solve. I have a program that has a NotifyIcon control. When the user completes the MainFrame form, the window minimizes and then hides. I want to be able to double-click the notifyicon to make the window reappear. I also want to be able to right-click the n-icon and have my context menu strip show. Now this works perfectly well when the window (MainFrame) is minimized, but once the user completes the MF form and the window hides, the n-icon does not respond. Here's my code: private void MainFrm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) Hide(); } ... private void TB_Icon_DoubleClick(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } ... private void TB_Icon_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContMenuStrip.Show(); } } ... private void ContMenuStrip_Click(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running. Nothing happens when I double-click or right-click on the notifyicon. Thanks for the help.

            D Offline
            D Offline
            danielhasdibs
            wrote on last edited by
            #6

            I have tried the ShowInTaskbar approach, but still, no dice. I tried to "run to cursor" to the point where the double-click event occurs, but it never goes to it. So, obviously, the icon does not recognize any mouse clicks. Is there a way to ensure that it does?

            D 1 Reply Last reply
            0
            • D danielhasdibs

              I have tried the ShowInTaskbar approach, but still, no dice. I tried to "run to cursor" to the point where the double-click event occurs, but it never goes to it. So, obviously, the icon does not recognize any mouse clicks. Is there a way to ensure that it does?

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #7

              danielhasdibs wrote:

              Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running

              This could be where your problem lies. How are you calling this loop and what's happening in it?

              Dave

              D 1 Reply Last reply
              0
              • D DaveyM69

                danielhasdibs wrote:

                Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running

                This could be where your problem lies. How are you calling this loop and what's happening in it?

                Dave

                D Offline
                D Offline
                danielhasdibs
                wrote on last edited by
                #8

                This is a reminder program. On the MainFrame form, the user enters a time to be reminded. After the reminder is set (the user clicks OK), the window minimizes and hides. Then the program enters a loop checking the difference in timespan. When the timespan.minutes is less than one, the reminder activates. I had the thread sleeping between iterations just to keep the memory usage down, but even when I remove the sleep methods, the icon does not respond.

                1 Reply Last reply
                0
                • D danielhasdibs

                  Ok, hopefully, this will be an easier problem to solve. I have a program that has a NotifyIcon control. When the user completes the MainFrame form, the window minimizes and then hides. I want to be able to double-click the notifyicon to make the window reappear. I also want to be able to right-click the n-icon and have my context menu strip show. Now this works perfectly well when the window (MainFrame) is minimized, but once the user completes the MF form and the window hides, the n-icon does not respond. Here's my code: private void MainFrm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) Hide(); } ... private void TB_Icon_DoubleClick(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } ... private void TB_Icon_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContMenuStrip.Show(); } } ... private void ContMenuStrip_Click(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running. Nothing happens when I double-click or right-click on the notifyicon. Thanks for the help.

                  D Offline
                  D Offline
                  danielhasdibs
                  wrote on last edited by
                  #9

                  Please see my last comment explaining what the program does.

                  1 Reply Last reply
                  0
                  • D danielhasdibs

                    Ok, hopefully, this will be an easier problem to solve. I have a program that has a NotifyIcon control. When the user completes the MainFrame form, the window minimizes and then hides. I want to be able to double-click the notifyicon to make the window reappear. I also want to be able to right-click the n-icon and have my context menu strip show. Now this works perfectly well when the window (MainFrame) is minimized, but once the user completes the MF form and the window hides, the n-icon does not respond. Here's my code: private void MainFrm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) Hide(); } ... private void TB_Icon_DoubleClick(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } ... private void TB_Icon_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContMenuStrip.Show(); } } ... private void ContMenuStrip_Click(object sender, EventArgs e) { Show(); WindowState = FormWindowState.Normal; } Now, keep in mind that after the user completes the MainFrame form (clicks the "OK" button), a loop is constantly running. Nothing happens when I double-click or right-click on the notifyicon. Thanks for the help.

                    A Offline
                    A Offline
                    Aurelius1664
                    wrote on last edited by
                    #10

                    I'm guessing your loop is preventing you main window from processing messages. You could identify this by putting an Application.DoEvents() line into the loop which should resume processing. However, this is bad and should not be seen as a solution only a test to see if it is message processing. The better approach would be to have your okay button start a timer rather than wait in a loop. You can use a timer control which should be able to do what you require.

                    D 1 Reply Last reply
                    0
                    • A Aurelius1664

                      I'm guessing your loop is preventing you main window from processing messages. You could identify this by putting an Application.DoEvents() line into the loop which should resume processing. However, this is bad and should not be seen as a solution only a test to see if it is message processing. The better approach would be to have your okay button start a timer rather than wait in a loop. You can use a timer control which should be able to do what you require.

                      D Offline
                      D Offline
                      danielhasdibs
                      wrote on last edited by
                      #11

                      I've tried the timer, but it still doesn't work. Could you give me a sample code that works for you using a timer (or a loop) and a NotifyIcon? Thanks.

                      D 1 Reply Last reply
                      0
                      • D danielhasdibs

                        I've tried the timer, but it still doesn't work. Could you give me a sample code that works for you using a timer (or a loop) and a NotifyIcon? Thanks.

                        D Offline
                        D Offline
                        DaveyM69
                        wrote on last edited by
                        #12

                        public partial class MainFrm : Form
                        {
                        Timer MyReminder = new Timer();

                            public MainFrm()
                            { 
                                InitializeComponent();
                                btnOK.Click += new EventHandler(btnOK\_Click);
                                Resize += new EventHandler(MainFrm\_Resize);
                                TB\_Icon.Icon = Icon;
                                TB\_Icon.MouseDoubleClick += new MouseEventHandler(TB\_Icon\_MouseDoubleClick);
                                ContMenuStrip.Click += new EventHandler(ContMenuStrip\_Click);
                                MyReminder.Interval = 2000; // 2 seconds
                                MyReminder.Tick += new EventHandler(MyReminder\_Tick);
                            }
                        
                            void MyReminder\_Tick(object sender, EventArgs e)
                            {
                                // Reminder stuff goes here
                                Console.WriteLine("You have been reminded at " + DateTime.Now); 
                            } 
                            void btnOK\_Click(object sender, EventArgs e)
                            { 
                                WindowState = FormWindowState.Minimized;
                            } 
                            void MainFrm\_Resize(object sender, EventArgs e)
                            {
                                if (WindowState == FormWindowState.Minimized)
                                {
                                    Hide();
                                    MyReminder.Start();
                                }
                                else
                                {
                                    MyReminder.Stop();
                                }
                            } 
                            void TB\_Icon\_MouseDoubleClick(object sender, MouseEventArgs e)
                            { 
                                Show();
                                WindowState = FormWindowState.Normal;
                            } 
                            void ContMenuStrip\_Click(object sender, EventArgs e) 
                            { 
                                Show(); 
                                WindowState = FormWindowState.Normal;
                            } 
                        }
                        

                        Dave

                        D 1 Reply Last reply
                        0
                        • D DaveyM69

                          public partial class MainFrm : Form
                          {
                          Timer MyReminder = new Timer();

                              public MainFrm()
                              { 
                                  InitializeComponent();
                                  btnOK.Click += new EventHandler(btnOK\_Click);
                                  Resize += new EventHandler(MainFrm\_Resize);
                                  TB\_Icon.Icon = Icon;
                                  TB\_Icon.MouseDoubleClick += new MouseEventHandler(TB\_Icon\_MouseDoubleClick);
                                  ContMenuStrip.Click += new EventHandler(ContMenuStrip\_Click);
                                  MyReminder.Interval = 2000; // 2 seconds
                                  MyReminder.Tick += new EventHandler(MyReminder\_Tick);
                              }
                          
                              void MyReminder\_Tick(object sender, EventArgs e)
                              {
                                  // Reminder stuff goes here
                                  Console.WriteLine("You have been reminded at " + DateTime.Now); 
                              } 
                              void btnOK\_Click(object sender, EventArgs e)
                              { 
                                  WindowState = FormWindowState.Minimized;
                              } 
                              void MainFrm\_Resize(object sender, EventArgs e)
                              {
                                  if (WindowState == FormWindowState.Minimized)
                                  {
                                      Hide();
                                      MyReminder.Start();
                                  }
                                  else
                                  {
                                      MyReminder.Stop();
                                  }
                              } 
                              void TB\_Icon\_MouseDoubleClick(object sender, MouseEventArgs e)
                              { 
                                  Show();
                                  WindowState = FormWindowState.Normal;
                              } 
                              void ContMenuStrip\_Click(object sender, EventArgs e) 
                              { 
                                  Show(); 
                                  WindowState = FormWindowState.Normal;
                              } 
                          }
                          

                          Dave

                          D Offline
                          D Offline
                          danielhasdibs
                          wrote on last edited by
                          #13

                          Thank you, thank you! Solution is above. Thanks to DaveyM69.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups