表单中的文本框和标签,并以另一种形式访问它

时间:2014-10-09 23:50:05

标签: vb.net

我试图在StudentRegistration表单中访问3个文本框和1个标签 我通过一个模块宣布它为公众。

Module StudentInfo

Public student_no As String = StudentRegistration.lblstudentno.Text
Public lastname As String = StudentRegistration.txtlastname.Text
Public firstname As String = StudentRegistration.txtfirstname.Text
Public middlename As String = StudentRegistration.txtmiddlename.Text

End Module  

我试图将其设置为另一种形式,但是在我加载表单时它无法自动显示。
你能帮助我吗???

Private Sub Payment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

student_no = lblstudentno.Text
 lastname = lbllastname.Text  
 firstname = lblfirstname.Text  
 middlename = lblfirstname.Text

End Sub

1 个答案:

答案 0 :(得分:0)

我尝试在visual basic中重现上面的代码,假设"付款" form包含四个标签,分别名为lblstudentno,lbllastname,lblfirstname和lblmiddlename(不是lblfirstname ...)。我并不反对使用具有模块级范围的变量。我同意" OneFineDay"在#34;付款"中,变量及其各自的值应该反之亦然。形成。像下面这样......

Private Sub Payment_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    lblstudentn.Text = student_no
    lbllastname.Text = lastname
    lblfirstname.Text = firstname
    lblmiddlename.Text = middlename

End Sub

此外,我想提一下,student_no,lastname等值仅在我第一次在" StudentRegistration"中的文本框中写入一些文本时才更改。形成。而不是在StudentInfo"模块"中初始化变量,我建议只是声明模块中的变量如下......

Module StudentInfo

    Public student_no As String
    Public lastname As String
    Public firstname As String
    Public middlename As String

End Module

...然后,在某些情况下"付款"表单加载,更新变量的值。

Public Class StudentRegistration

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles    Button1.Click
        student_no = lblstudentno.Text
        lastname = txtlastname.Text
        firstname = txtfirstname.Text
        middlename = txtmiddlename.Text
        Payment.Show()
    End Sub
End Class

我不确定这一切是否都适用于vb.net,但我希望我的评论有用!!