本文介绍了不能始终如一地把表单前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过几件事情,但他们没有工作...



我有表应该进来的所有Windows门前点击的NotifyIcon。因此,这里是我的尝试:

 私人无效notifyIcon1_MouseDown(对象发件人,MouseEventArgs E)
{
如果(e.Button == MouseButtons.Left)
{
this.TopMost = TRUE;
this.BringToFront();
this.Focus();
this.TopMost = FALSE;
}
}



然后我试图使用SetForegroundWindow:



  [返回:的MarshalAs(UnmanagedType.Bool)
函数[DllImport(USER32,字符集= CharSet.Ansi,SetLastError =真,ExactSpelling = TRUE)]
公共静态的extern BOOL SetForegroundWindow(IntPtr的HWND);



加入

  SetForegroundWindow(this.Handle); 



在IF块的结尾。



最后,我看到的时候,如果我点击的NotifyIcon和上下文菜单中单击鼠标右键不起作用被打开了,然后我就可以离开了点击的NotifyIcon和它带来的正面。



我试图在开始添加以下代码:

  cmsNotifyIcon.Show(); 
cmsNotifyIcon.Close();



所以,它显示并关闭NotifyIcon的上下文菜单,作为解决办法一个可能的想法,但它不 ŧ帮助。



这是如何做到这一点,或变通解决此?


解决方案

如果你做它的MouseUp?


I've tried several things, but none of them work...

I have Form that should come in front of all Windows on clicking NotifyIcon. So here is what I tried:

private void notifyIcon1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        this.TopMost = true;
        this.BringToFront();
        this.Focus();
        this.TopMost = false;
    }
}

Then I tried to use SetForegroundWindow:

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool SetForegroundWindow(IntPtr hwnd);

by adding

        SetForegroundWindow(this.Handle);

at the end of the if block.

Finally, I saw that when this doesn't work if I click right mouse button on NotifyIcon and context menu gets opened, I can then left click NotifyIcon and it brings it to the front.

I've tried to add this code at the beginning:

        cmsNotifyIcon.Show();
        cmsNotifyIcon.Close();

So that it shows and closes notifyIcon context menu, as a possible idea for workaround, but it doesn't help.

Any ideas on how to do this, or work around this?

解决方案

what if you do it on MouseUp ?

这篇关于不能始终如一地把表单前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 01:10