NotifyIcon does not respond
-
I changed it to MouseDoubleClick and the ContMenuStrip is already assigned to the ContextMenuStrip property of TB_Icon. Still, the icon does not respond.
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
-
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.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.
-
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.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?
-
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?
-
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
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.
-
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.Please see my last comment explaining what the program does.
-
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.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.
-
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.
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.
-
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.
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
-
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
Thank you, thank you! Solution is above. Thanks to DaveyM69.