最近想改托盘图标点击事件,点一次显示,再点一次隐藏,如果窗体是最小化状态则恢复显示。请问点击任务栏图标窗体最小化那个事件是哪个?或者怎么知道窗体状态改变事件???现在显示窗体后点任务栏图标,窗体状态没变成最小化啊。
private void NITodoList_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.Visible) { //如果窗体最小化则恢复显示,否则隐藏 if (this.WindowState == FormWindowState.Minimized) { ShowWindowMgr.ShowWindowAsync(this.Handle, ShowWindowMgr.SW_RESTORE); this.WindowState = FormWindowState.Normal; } else { ShowWindowMgr.ShowWindow(this, ShowWindowState.Hide); } } else { //如果窗体隐藏则显示 ShowWindowMgr.ShowWindow(this, ShowWindowState.RunningShow); ShowWindowMgr.SetForegroundWindow(this); } } }
目前底部的RunningShow设置的窗体为Normal,而Hide设置的Minimized
已解决,用API函数进行判断。
[DllImport("user32.dll")] public static extern bool IsIconic(IntPtr hWnd);
private void NITodoList_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.Visible) { //如果窗体最小化则恢复显示,否则隐藏 if (ShowWindowMgr.IsIconic(this.Handle)) { ShowWindowMgr.ShowWindowAsync(this.Handle, ShowWindowMgr.SW_RESTORE); this.WindowState = FormWindowState.Normal; } else { ShowWindowMgr.ShowWindow(this, ShowWindowState.Hide); } } else { //如果窗体隐藏则显示 ShowWindowMgr.ShowWindow(this, ShowWindowState.RunningShow); ShowWindowMgr.SetForegroundWindow(this); } } }