我有一个在停用时最小化的表单,但现在任务栏按钮不会最小化表单。它消失了然后回来了。似乎与任务栏功能和停用事件竞争,当我单击图标时表单最小化,然后任务栏功能看到它被最小化并且表单恢复。我有以下代码:
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);
}
(请注意,表单没有控件)
我能够通过以下乐队获得它的工作:
private void focusTimerEvent(object o, EventArgs e)
{
WindowState = FormWindowState.Minimized;
focusTimer.Stop();
}
private void lostFocus(object o, EventArgs e)
{
focusTimer.Start();
}
并在Form1()方法中将计时器设置为1000
focusTimer = new Timer();
focusTimer.Interval = 1000;
focusTimer.Tick += focusTimerEvent;
任何建议都将不胜感激