简体   繁体   English

打开时尚未选择 VB.NET 窗体

[英]VB.NET form not already selected when opened

I open a custom form from another with ShowDialog(),我使用 ShowDialog() 从另一个表单打开一个自定义表单,

The problem is that this freshly opened form is not already selected, but just on top.问题是这个新打开的表单还没有被选中,而只是在上面。 This causes that I can't capture key presses or have my first tab index already selected until I click once on the form .这导致我无法捕获按键或已选择我的第一个选项卡索引,直到我在表单上单击一次

Anyone can help me ?任何人都可以帮助我吗?

I already tried these in the Form_Load and it doesn't work yet :我已经在 Form_Load 中尝试过这些,但还没有工作:

Me.Activate()
Me.BringToFront()
Me.Focus()
Me.Show()
Me.Select()

I did not found an answer yet from searching on Google.我还没有通过谷歌搜索找到答案。

It sounds you have a timer or a handler that handles and focus on the above form so you loose the focus on the freshly dialogued form.听起来您有一个timerhandlerhandlesfocus上述表单,因此您将注意力集中在新对话的表单上。

Solution: - Remove the loop or handler that focus on your form and do it on a background or something more external or after the Form_Load.解决方案: - 删除关注您的表单的循环或处理程序,并在背景或更外部的内容上或在 Form_Load 之后执行此操作。

*To be clear: when you use ShowDialog() the form will be shown on TopMost so the other form will be sent to the front you cant focus on it till the Dialog will be closed *要清楚:当您使用 ShowDialog() 时,表单将显示在 TopMost 上,因此另一个表单将被发送到前面,您无法专注于它,直到 Dialog 关闭

You should try this if you don't have a very slow computer :如果你的电脑不是很慢,你应该试试这个:

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

   ClickForm.Interval(1000)
   ClickForm.Start()

   'Set the interval and start the timer

End Sub

Private Sub ClickForm_Tick(sender As Object, e As EventArgs) Handles ClickPanel.Tick
   'Wait for form charging

    Me.Select()

   'Select the form

End Sub

Obviously you need to add a timer to your project...显然你需要在你的项目中添加一个计时器......

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

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