0

我有一个在停用时最小化的表单,但现在任务栏按钮不会最小化表单。它消失了一段时间然后又回来了。任务栏功能和停用事件似乎存在竞争,当我单击表单最小化的图标时,任务栏功能会看到它被最小化并且表单恢复。我有以下代码:

 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;

任何建议,将不胜感激

4

0 回答 0