简体   繁体   English

开始后将重点放在winform上

[英]Set focus on winform after start

I found a few topics about this but none of these could help me with my problem, i want to set the focus on a new created winform window after it started. 我找到了一些关于这个的主题,但这些都没有帮助我解决我的问题,我想在开始之后将焦点放在新创建的winform窗口上。

I'm starting the form in a own new thread with: 我在一个自己的新线程中启动表单:

application.Run(new InvisibleForm());

and the form appears, but the focus is still set on the last selected window from windows. 并且表单出现,但焦点仍然是从窗口最后选择的窗口设置的。 this form has no titlebar and is not in the taskpanel to see, it also has a TransparencyKey set: 此表单没有标题栏,并且不在任务面板中查看,它还具有TransparencyKey集:

this.AutoScaleDimensions = new SizeF(6F, 13F);
this.AutoScaleMode = AutoScaleMode.Font;
this.BackColor = SystemColors.AppWorkspace;
this.ClientSize = new Size(992, 992);
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InvisibleForm";
this.Opacity = 0.5;
this.ShowInTaskbar = false;
this.TransparencyKey = SystemColors.AppWorkspace;
this.Load += new EventHandler(this.InvisibleForm_Load);

now i tried a few methods but none of these got me focus on the form or could set the form on the foreground / of top of all other windows: 现在我尝试了一些方法,但没有一个让我专注于表单或可以在前台/所有其他窗口的顶部设置表单:

this.TopMost = true;
this.Focus();
this.BringToFront();
this.Activate();

is there a way to fire programmly a click / focus event to the form so that it sets himself with this event on focus ? 有没有办法可以将一个点击/焦点事件发送到表单,以便在焦点上设置自己的事件?

在表单的“显示”状态下使用Activate()方法很重要,因此为显示的事件创建一个监听器并在那里使用你的focus / front方法

you can trying this code 你可以试试这段代码

this.ShowDialog();

the code above same as MessageBox with attention. 上面的代码与MessageBox相同,注意。 So the last form appear must close and can access the other form again. 因此,最后一个表单必须关闭,并且可以再次访问另一个表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM