表格失去焦点 - 基本问题 [英] Form lost focus - Basic Question

查看:168
本文介绍了表格失去焦点 - 基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#Windows窗体应用程序,与所有默认设置。我使用VS 2008,OS - Windows Vista中

I have C# windows form application, with all default settings. I am using VS 2008, OS - Windows VIsta.

在我的表单失去焦点,(如当在形式背后的东西,用户点击),我需要在同一。失去焦点的形式来恢复它

When my form loses focus, (as in when a user clicks on something behind the form), i need the same form that lost focus to regain it.

我利用这一事件来处理这一点;

I made use of this Event to handle this;

private void Form1_Deactivate_1(object sender, EventArgs e)
{

  Console.WriteLine("DEACTIVATE EVENT _______+++++++++_________");
   Form1 f = new Form1();
  f.show();
}



在这里,你将看到的是,当窗体失去它的焦点, Console.WriteLine命令命令将执行一个新的形式出现在屏幕上。我不想要这个。我想,失去焦点重新聚焦和背部出现在屏幕上的确切形式。我如何做到这一点。

Here, what you will see is that is when the form loses its focus, the Console.writeline command will execute and a new form will appear on the screen. I do not want this. i want the exact form that lost focus to regain focus and appear back on the screen. How do i do this.

推荐答案

Form.Activate 方法激活的形式并给予其焦点:

Form.Activate methods activates the form and gives it focus:

form.Activate();

Form.TopMost 属性指示表单是否应显示为最顶层的形式。结果
最顶层形式是形式重叠的所有其它(非最顶层),即使它不是活性或前景形式的形式。最上面的形式始终在桌面上的窗口的z顺序的最高点显示。

Form.TopMost Property indicates whether the form should be displayed as a topmost form.
A topmost form is a form that overlaps all the other (non-topmost) forms even if it is not the active or foreground form. Topmost forms are always displayed at the highest point in the z-order of the windows on the desktop.

form.TopMost = true;

这篇关于表格失去焦点 - 基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆