在C#Windows Forms Application中,如何将表单放到前面? [英] In C# Windows Forms Application, how to bring a form to front?

查看:78
本文介绍了在C#Windows Forms Application中,如何将表单放到前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户将程序最小化并按下F3时,全局挂钩键将获得按下并转换窗口并将其显示在前面。



这些'总是有效:



(f = new FormDefineWord())。Show();

f.WindowState = FormWindowState.Normal;

f.BringToFront();

F.Topmost = true;



如何强制新表格到被带到前面并专注于?

When the user has the program minimized and presses F3 a global hook keys gets the press and translation window should be made and brought to front.

These don't always work:

(f = new FormDefineWord()).Show();
f.WindowState = FormWindowState.Normal;
f.BringToFront();
F.Topmost=true;

How to force the new form to be brought to front and focused on?

推荐答案

尝试使用计时器。首先只显示窗口并激活计时器以在大约50或100毫秒内运行。然后在计时器事件中,您可以调用BringToFront或将其设置为TopMost或您最喜欢的任何内容。



问题是您创建窗口并尝试使用相同的方法设置其属性。调用BringToFront不起作用,因为还没有表单。这必须通过相同的事件循环启动。之后你可以改变它的属性。



祝你好运!
Try use a timer. First only show the window and activate a timer to run in about 50 or 100ms. Then in the timer event you call the BringToFront or set it to TopMost or whatever you like best.

The problem is that you create the window and try to set its properties in the same method. Calling BringToFront does not work because there is no form yet. This has to go through the same event looping to start up. After that you can change its properties.

Good luck!


添加Focus()调用应该可以解决问题。 />


Adding Focus() call should do the trick.

(f = new FormDefineWord()).Show();
f.WindowState = FormWindowState.Normal;
f.BringToFront();
f.Topmost=true;
f.Focus();


这对我有用

VS 2010

假设这是需要关注的当前形式。



this works for me
VS 2010
assuming this is current form for which focus is needed.

this.Show();
     this.WindowState = FormWindowState.Normal;
     this.BringToFront();
     this.TopLevel = true;
     this.Focus();


这篇关于在C#Windows Forms Application中,如何将表单放到前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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