创建一个非常简单的 Visual Basic 代码卡在一步

creating a very simple Visual Basic code stuck on one step

我正在制作一个非常简单的 Visual Basic 代码,我遇到的问题是当程序 运行 时文本框有文字。 我希望文本框显示 "My name is John",当您单击按钮时,它会变为 "and this is my first VB program"。 这也是我编写的代码:

Public Class frmMain

Private Sub btnClickMe_Click(sender As System.Object, e As System.EventArgs)Handles btnClickMe.Click

    txtOutPut.Text = "My name is John"
    txtOutPut.Text = "and this is my first VB program"

End Sub
End Class

是的,很抱歉这个简单的问题失败了,但谢谢,我真的很感激。

Public Class frmMain

Private Sub btnClickMe_Click(sender As System.Object, e As System.EventArgs)Handles btnClickMe.Click

    txtOutPut.Text = "My name is John" & VbCrLf & "and this is my first VB program"

End Sub
End Class

尝试将文本设置为 "My name is John" 在按钮点击之外,也许是在 Form.Init 处理程序中,然后从 btnClickMe_Click1

中删除 txtOutPut.Text = "My name is John"

这里发生的事情是单击按钮首先将文本更改为 "My name is John",然后将其更改为 "and this is my first VB program",并且更改发生得太快以至于无法看到。

您在加载表单时需要 txtOutPut.Text = "My name is John"(或者直接在设计过程中,放置文本框后转到属性并将 "My name is John" 放入文本 属性),您按钮中包含所有内容,因此当您按下按钮时,它首先执行 txtOutPut.Text = "My name is John",然后执行 txtOutPut.Text = "and this is my first VB program",然后覆盖 "My name is John",因此一旦按下按钮,您总是会看到 "and this is my first VB program"按钮。