如何将文本从用户名转移到另一个表单? (VB.NET)

时间:2018-04-08 12:57:48

标签: vb.net

我对VB.NET和编程很新,所以请耐心等待。

我正在开发一种“博客”应用程序,我的第一个表单是登录表单,我想从登录表单中获取用户名并将其放入博客表单中。

以下是我在博客表格中的内容:

Public Class Form1
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
    Dim X As Boolean


    If txtBlog.Text = String.Empty Then
        X = False
    Else
        X = True

    End If

    If X = True Then
        lblMessage1.Text = txtBlog.Text
        txtBlog.Hide()
        btnSubmit.Hide()
    End If

End Sub

以下是我登录表单的内容:

Public Class login
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
    If txtUser.Text = "admin" And txtPassw.Text = "password" Then
        Form1.Show()
        Me.Hide()
    Else
        MessageBox.Show("Invalid Login")
        txtPassw.Text = ""
        txtUser.Text = ""
    End If
End Sub

谢谢!

1 个答案:

答案 0 :(得分:0)

创建类login()的新实例,允许您访问该实例的变量

试试这个:

Public Class Form1
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
    Dim X As Boolean
    Dim userName As String

dim Z as new login()
userName=Z.txtUser.Text 


    If txtBlog.Text = String.Empty Then
        X = False
    Else
        X = True

    End If

    If X = True Then
        lblMessage1.Text = txtBlog.Text
        txtBlog.Hide()
        btnSubmit.Hide()
    End If

End Sub