I'm trying to make it so that when you double click the tray icon, my program will either a) minimize if it is in the normal state, or b) return to normal state if it is minimized.
I have the following code (where TrayIcon is a NotifyIcon control):
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void TrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (MainForm.ActiveForm.WindowState == FormWindowState.Normal)
{
MainForm.ActiveForm.WindowState = FormWindowState.Minimized;
}
else
{
MainForm.ActiveForm.WindowState = FormWindowState.Normal;
}
}
}
However, when i run the code and double click the icon, it gives me a NullReferenceException and says (on the 'if' line) that the Object Reference is not set to an instance of an object.
I'm not quite sure what to do.