以编程方式设置焦点时,窗体边框和主题闪烁
Form border and topic blinks when setting focus programmatically
我有一个通常隐藏的应用程序,但我希望它在我将鼠标光标移动到屏幕上的特定位置时获得焦点。
我已尝试使用以下代码来激活表单:
this.Show();
this.BringToFront();
this.Focus();
this.Activate();
也尝试添加这个:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
SetForegroundWindow(this.Handle);
无论我做什么,我的应用程序都没有从当前活动的应用程序中窃取焦点,而只是在没有获得焦点的情况下自行闪烁。
有没有其他方法可以强制窗体在前台突出焦点?
您可以尝试多种方式并选择适合您的方式。
这个应该总是把表格放在前面。
this.TopMost = true;
this.ShowDialog();
你也可以试试:
this.WindowState = FormWindowState.Minimized;
this.Show();
this.WindowState = FormWindowState.Normal;
另外:
this.BringToFront();
我有一个通常隐藏的应用程序,但我希望它在我将鼠标光标移动到屏幕上的特定位置时获得焦点。
我已尝试使用以下代码来激活表单:
this.Show();
this.BringToFront();
this.Focus();
this.Activate();
也尝试添加这个:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
SetForegroundWindow(this.Handle);
无论我做什么,我的应用程序都没有从当前活动的应用程序中窃取焦点,而只是在没有获得焦点的情况下自行闪烁。
有没有其他方法可以强制窗体在前台突出焦点?
您可以尝试多种方式并选择适合您的方式。
这个应该总是把表格放在前面。
this.TopMost = true;
this.ShowDialog();
你也可以试试:
this.WindowState = FormWindowState.Minimized;
this.Show();
this.WindowState = FormWindowState.Normal;
另外:
this.BringToFront();