我已经为按钮的点击事件编写了代码,但是当我在运行时点击它时什么也没发生。为什么?

时间:2018-04-18 10:27:27

标签: vb.net button msgbox

我正在使用VS2017和vb.net来创建一个简单的应用程序,该应用程序将输入作为用户的文本输入,当单击按钮时,它将在MsgBox中显示它。

然而,当我在buton的点击事件中编写代码时,没有任何反应。

请帮助。 在此先感谢:)

这里的守则 -

Public Class Form1

Dim a
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MsgBox("You Typed" + a + "!")
End Sub

结束班

1 个答案:

答案 0 :(得分:0)

试试这个:

Public Class Form1

Dim a as string
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MsgBox("You Typed" + a + "!")
End Sub

Private Sub keyentered(e As KeyEventArgs)
    If e.KeyCode = Keys.E Then
        a = "e"
MsgBox("You Typed" + a + "!")
    End If
End Sub

如果它不起作用,添加一个文本框,然后键入它,但是像这样:

Public Class Form1

Dim a as string
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    MsgBox("You Typed" + a + "!")
End Sub

Private Sub keyentered(e As KeyEventArgs)
    If e.KeyCode = Keys.E Then
        a = "e"
MsgBox("You Typed" + a + "!")
    End If
End Sub

private sub textbox1_textchanged(e As KeyEventArgs) Handeles Textbox1.textchanged

 If e.KeyCode = Keys.a Then
            a = "a"
    textbox1.text = ""
    MsgBox("You Typed" + a + "!")
        End If
    End Sub

end sub

EDIT1: 继续这样做,直到你到达Z

EDIT2: 确保你有keyeventargs而不是eventargs,否则你会收到错误。