为什么我的基本默认 .acceptbutton 不起作用? [英] Why is my basic default .acceptbutton is not working?

查看:20
本文介绍了为什么我的基本默认 .acceptbutton 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分组框,每个分组框里面都有一个文本框.第三个文本框放置在两个组框之外.

I have two group boxes each with a text box inside. A third text box is placed outside both of the group boxes.

按钮 1 是表单加载时的默认接受按钮.

Button 1 is the default accept button on form load.

当单击按钮 1(或按下 Enter 键)时,我需要按钮 2 成为默认的接受按钮.

When button 1 is clicked (or enter key is pressed), I need button 2 to become the default accept button.

尽管有我的代码,按钮 3 成为默认的接受按钮,而不是按钮 2.

Button 3 becomes the default accept button rather than button 2 in spite of my code.

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    GroupBox1.Enabled = True
    GroupBox2.Enabled = False
    Me.AcceptButton = Button1
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MessageBox.Show("Button 1 pressed!")
    GroupBox1.Enabled = False
    GroupBox2.Enabled = True
    Me.AcceptButton = Button2
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    MessageBox.Show("Button 2 pressed!")
    GroupBox1.Enabled = True
    GroupBox2.Enabled = False
    Me.AcceptButton = Button1
End Sub

End Class

推荐答案

问题是在你按下按钮 1 按钮 3 获得焦点后.
您可以通过将代码添加到按钮 1 单击事件中所需的按钮上来修复它.Button2.Focus()"等.

the problem is after you press button 1 button 3 gets focus.
you could fix it by adding code to focus to the button you need in the button 1 click event. "Button2.Focus()" etc..

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MessageBox.Show("Button 1 pressed!")
    GroupBox1.Enabled = False
    GroupBox2.Enabled = True
    Me.AcceptButton = Button2
    Button2.Focus()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    MessageBox.Show("Button 2 pressed!")
    GroupBox1.Enabled = True
    GroupBox2.Enabled = False
    Me.AcceptButton = Button1
    Button1.Focus()
End Sub

这篇关于为什么我的基本默认 .acceptbutton 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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