【问题标题】:VB.NET - Working with Multiple FormsVB.NET - 使用多种形式
【发布时间】:2015-08-22 21:43:01
【问题描述】:

我正在尝试创建一个登录窗口和一个主窗口。问题是当我关闭登录表单并显示主窗口时,整个程序停止。

登录表单:

Imports System.IO
Imports System.Text
Imports System.Net

Public Class frmLogin

    Dim address As String = "http://puu.sh/jKJ**Zq/d613de****29.txt"
    Dim client As WebClient = New WebClient()

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'frmMain.Close()
    End Sub

    Private Sub frmLogin_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosed
        frmMain.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If attemptLogin() Then
            MsgBox("Login Successful")
            Me.Close()
            'frmMain.Show()
        Else
            MsgBox("Username or password is incorrect")
        End If

    End Sub

    Private Function attemptLogin()
        Dim reader As StreamReader = New StreamReader(client.OpenRead(address))

        Dim line As String
        Dim username As String
        Dim password As String

        line = reader.ReadLine()

        Do While Not line Is Nothing

            username = line.Split(":")(0)
            password = line.Split(":")(1)

            If (username = TextBox1.Text And password = TextBox2.Text) Then
                Return True
            End If

            line = reader.ReadLine()

        Loop

        reader.Close()
        client.Dispose()

        Return False

    End Function

    Private Function Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim client As WebClient = New WebClient()
        Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
        Dim line As String

        line = reader.ReadLine

        Do While Not line Is Nothing
            line = reader.ReadLine()
        Loop

        reader.Close()
        Dim writer As StreamWriter = New StreamWriter(client.OpenRead(address))
        writer.Write(TextBox1.Text & ":" & TextBox2.Text)

        writer.Close()
        client.Dispose()

        Return False

    End Function

End Class

主窗口:

Public Class frmMain

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        'frmMain.Close()
    End Sub

    Private Sub frmMain_closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosing

    End Sub

End Class

我对 VB.NET 还很陌生,因此对缺乏知识/丑陋的编码感到抱歉。我习惯用 Java 编写 GUI。

【问题讨论】:

标签: vb.net forms user-interface


【解决方案1】:

您需要将“关闭模式”设置为“当最后一个表单关闭时”。

您可以通过转到我的项目然后单击应用程序(第一个选项卡)找到此设置。 然后您可以在底部找到设置。

【讨论】:

  • 哦,我的错,我不知道我能做到这一点。另一个问题,是程序启动时创建的两个表单,还是程序启动时我选择显示的表单?
  • 只是您选择的表格。但是您可以在第一个表单加载时使用 frmSecond.ShowDialog() 轻松打开第二个表单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-01
  • 1970-01-01
相关资源
最近更新 更多