Form lost focus - Basic Question

安稳与你 提交于 2019-12-23 22:27:44

问题


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();
}

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.


回答1:


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

form.Activate();

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;


来源:https://stackoverflow.com/questions/6401711/form-lost-focus-basic-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!