我刚刚开始使用 Visual Studio 学习 Visual Basic 自定进度课程。我分配的问题之一是创建一个带有两个按钮的表单。当表单加载时,Button1 被启用,Button2 被禁用。当您单击 Button1 时,Button1 被禁用,而 Button2 被启用。当您单击 Button2 时,Button2 将被禁用,而 Button1 将被启用。
我很容易做到这一点,所以我决定给自己增加一个额外的挑战。挑战是我想让禁用的按钮显示文本“禁用”,启用的按钮显示“启用”,并带有下划线的“E”作为按钮的热键。我为包含字符串“&Enabled”的启用按钮设置了一个字符串变量,以启用“E”作为热键。 “E”作为热键,但不显示下划线。
我在网上搜索了此问题的解决方案,但一无所获。我还尝试调整按钮的大小,看看按钮是否太小而无法显示下划线。那没有用。我已经仔细检查了我的代码,但我真的不太了解该语言,无法理解为什么“E”不显示下划线。我正在提交我的代码并寻求帮助。我想了解为什么这不能按我期望的方式工作。
这是我使用 Visual Studio 2019 为表单编写的 VB.Net 代码。
Public Class frmEnabledProblem
Dim blnButton1Enabled As Boolean = True
Dim blnButton2Enabled As Boolean = False
Dim strButton1Enabled As String = "&Enabled"
Dim strButton1Disabled As String = "Disabled"
Dim strButton2Enabled As String = "&Enabled"
Dim strButton2Disabled As String = "Disabled"
Private Sub frmEnabledProblem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
btnButton2.Text = strButton2Disabled
btnButton2.Enabled = False
btnButton1.Text = strButton1Enabled
btnButton1.Enabled = True
End Sub
Private Sub btnButton1_Click(sender As Object, e As EventArgs) Handles btnButton1.Click
blnButton1Enabled = False
blnButton2Enabled = True
btnButton1.Enabled = blnButton1Enabled
btnButton2.Enabled = blnButton2Enabled
btnButton1.Text = strButton1Disabled
btnButton2.Text = strButton2Enabled
End Sub
Private Sub btnButton2_Click(sender As Object, e As EventArgs) Handles btnButton2.Click
blnButton1Enabled = True
blnButton2Enabled = False
btnButton1.Enabled = blnButton1Enabled
btnButton2.Enabled = blnButton2Enabled
btnButton1.Text = strButton1Enabled
btnButton2.Text = strButton2Disabled
End Sub
End Class
感谢您的帮助。