I have a form that that minimizes on deactivate but now the task bar button does not minimize the form. It goes away for an instance then comes back. There seems to be a race with the task bar function and the deactivate event where when I click the icon the form minimizes, then the task bar function sees that it is minimized and the form restores. I have the following code:
public Form1()
{
InitializeComponent();
Text = string.Empty;
ControlBox = false;
FormBorderStyle = FormBorderStyle.SizableToolWindow;
Deactivate += lostFocus;
}
private void lostFocus(object o, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
protected override void WndProc(ref Message message)
{
const int WM_NCHITTEST = 0x0084;
if (message.Msg == WM_NCHITTEST) return;
base.WndProc(ref message);
}
(Note that the form has no controls)
I was able to get it to kind of work with the following bandade:
private void focusTimerEvent(object o, EventArgs e)
{
WindowState = FormWindowState.Minimized;
focusTimer.Stop();
}
private void lostFocus(object o, EventArgs e)
{
focusTimer.Start();
}
and setting the timer to 1000 in Form1() method
focusTimer = new Timer();
focusTimer.Interval = 1000;
focusTimer.Tick += focusTimerEvent;
any suggestions would be appreciated