我的应用程序通常是隐藏的,但是当我将鼠标光标移动到屏幕上的特定位置时,我希望它能获得焦点。
我尝试使用以下代码来激活表单:
this.Show();
this.BringToFront();
this.Focus();
this.Activate();
还尝试添加此内容:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
SetForegroundWindow(this.Handle);
无论我做什么,我的应用程序都没有从当前活跃的应用程序中窃取焦点,但只有在没有获得关注的情况下才能自我眨眼。
是否还有其他方法可以强制表单前景和聚焦?
答案 0 :(得分:1)
您可以尝试多种方法并选择适合您的方式 这个应该始终把形式带到前面。
this.TopMost = true;
this.ShowDialog();
您也可以尝试:
this.WindowState = FormWindowState.Minimized;
this.Show();
this.WindowState = FormWindowState.Normal;
此外:
this.BringToFront();