问题
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