【发布时间】:2012-04-19 08:44:09
【问题描述】:
我发现了一些关于此的主题,但这些都不能帮助我解决我的问题,我想在新创建的 winform 窗口启动后将焦点设置在它上。
我在自己的新线程中开始表单:
application.Run(new InvisibleForm());
并出现窗体,但焦点仍设置在 windows 中最后一个选定的窗口上。这个表单没有标题栏,不在任务面板中看到,它还有一个 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);
现在我尝试了一些方法,但这些方法都没有让我专注于表单,或者可以将表单设置在所有其他窗口的前景/顶部:
this.TopMost = true;
this.Focus();
this.BringToFront();
this.Activate();
有没有办法以编程方式将点击/焦点事件触发到表单,以便它将此事件设置为焦点?
【问题讨论】:
-
您在何处/何时设置所有这些属性?在 Shown 事件中尝试
this.Focus()。 -
旁白:在自己的线程上运行表单是可能的,但很少是一个好主意。
-
有趣,它对我有用。你在 this.InvisibleForm_Load 中做什么?
-
我只看到了 this.show 并没有注意到我们也有 this.shown ...所以它还在工作 ;) 谢谢 dood
标签: c# .net winforms focus setfocus