c# – 不能始终如一地将形式带到前面
发布时间:2020-12-15 08:32:34 所属栏目:百科 来源:网络整理
导读:我尝试了几件事,但没有一件能起作用…… 我点击NotifyIcon时应该在所有Windows前面的Form.所以这是我尝试过的: private void notifyIcon1_MouseDown(object sender,MouseEventArgs e){ if (e.Button == MouseButtons.Left) { this.TopMost = true; this.Bri
我尝试了几件事,但没有一件能起作用……
我点击NotifyIcon时应该在所有Windows前面的Form.所以这是我尝试过的: private void notifyIcon1_MouseDown(object sender,MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.TopMost = true; this.BringToFront(); this.Focus(); this.TopMost = false; } } 然后我尝试使用SetForegroundWindow: [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32",CharSet = CharSet.Ansi,SetLastError = true,ExactSpelling = true)] public static extern bool SetForegroundWindow(IntPtr hwnd); 通过增加 SetForegroundWindow(this.Handle); 在if块的末尾. 最后,我看到如果我在NotifyIcon上单击鼠标右键并且上下文菜单打开时不起作用,我可以左键单击NotifyIcon并将其带到前面. 我试图在开头添加此代码: cmsNotifyIcon.Show(); cmsNotifyIcon.Close(); 因此它显示和关闭notifyIcon上下文菜单,作为解决方法的可能想法,但它没有帮助. 关于如何做到这一点的任何想法,或解决这个问题? 解决方法
如果你在MouseUp上做了怎么办?
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |