0

我正在尝试在登录屏幕中连接到数据库(我选择的 mdb 文件),我想保存它以便下次启动软件时更快地登录。

我单击选择数据库按钮,opendialog 让我选择文件,我单击确定,数据库位置显示在文本框中。在我连接之前,下面有一个复选框可以保存它。

但是我无法保持选中复选框,也无法在重新启动程序后填充文本框。

这是我当前的代码:

    Public Class LoginScreen
    
        Private Sub Loginscreen_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ProgressBar2.Minimum = 0
            ProgressBar2.Maximum = 100
            ProgressBar2.Visible = False
            Panel1.Visible = False
    
        End Sub
        Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
            Application.Exit()
        End Sub
        Private Sub btnExit2_Click(sender As Object, e As EventArgs) Handles btnExit2.Click
            Application.Exit()
        End Sub
    
        Private Sub tmrLogin_Tick(sender As Object, e As EventArgs) Handles tmrLogin.Tick
            ProgressBar2.Value = ProgressBar2.Value + 20
            lblLoginMessages.Text = ProgressBar2.Value & "%" & " Completed"
            If ProgressBar2.Value >= 100 Then
                tmrLogin.Enabled = False
                If txtUser.Text = "azert" And txtPassword.Text = "azert" Then
                    ProgressBar2.Value = 0
                Else
                    lblLoginMessages.Text = "Wrong credentials, Try again!"
                    pboxClosed.Visible = True
                    PboxOpen.Visible = False
    
                    ProgressBar2.Value = 0
                    txtPassword.Text = ""
                    txtUser.Text = ""
                End If
            End If
        End Sub
    
        Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
            ProgressBar2.Visible = True
            tmrLogin.Enabled = True
    
            pboxClosed.Visible = False
            PboxOpen.Visible = True
            ''navraag doen om dit correct in te stellen! ! ! ! !! 
            'If ProgressBar2.Value = 100 Then
            'lblLoginMessages.Text = "Logging in..."
            Me.Hide()
                Mainscreen.Show()
            'End If
            If chkSavePassword.Checked = True Then
                My.Settings.databaselocation = txtDatabaselocationshow.Text
                My.Settings.SaveLocation = True
    
    
            End If
        End Sub
    
        Private Sub btnDBConnect_Click(sender As Object, e As EventArgs) Handles btnDBConnect.Click
            If Panel1.Visible = False Then
                Panel1.Visible = True
            Else
                Application.Exit()
    
            End If
        End Sub
    
        Private Sub btnChoose_Click(sender As Object, e As EventArgs) Handles btnChoose.Click
            Dim strtext As String
            OpenFileDialog1.Filter = "Database Files | *.mdb"
            OpenFileDialog1.InitialDirectory = "F:\GoogleDrive\EINDWERK VBNET"
            OpenFileDialog1.Title = "Choose your Database"
            OpenFileDialog1.ShowDialog()
    
            strtext = OpenFileDialog1.FileName
            txtDatabaselocationshow.Text = strtext
            'If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            '    strtext = OpenFileDialog1.FileName
            '    txtDatabaselocationshow.Text = strtext
            'Else
            '    MsgBox("Error: the database file could not be read, try again.")
            'End If
    
        End Sub
    
        Private Sub tmrshowloginpanel_Tick(sender As Object, e As EventArgs) Handles tmrshowloginpanel.Tick
            Panel1.Width += 5
            If Panel1.Width >= 700 Then
                tmrshowloginpanel.Stop()
            End If
        End Sub
    
    End Class

我已经搜遍了网络,但真的找不到该怎么办?

如果您需要更多信息,请拍摄!

4

1 回答 1

2

跟我一起来看看:

  • 创建一个新项目,一个表单,添加一个文本框和一个组合框。

  • 点击文本框:

在此处输入图像描述

  • 在顶部的属性网格中单击(Application Settings) ,然后单击Property Binding旁边的 3 个点。滚动到文本。下拉设置并选择底部的新建。

在此处输入图像描述

  • 给它一个名称ChosenDatabasePath或类似的有用和描述性的名称

在此处输入图像描述

  • 重复复选框的“单击文本框”,这次绑定 Checked属性而不是Text属性。调用复选框的 Checked 绑定SavePassword或类似

  • 关闭所有对话框,以便您返回表单

  • 在属性网格中切换到Events时点击表单背景任意位置,找到FormClosing并双击

在此处输入图像描述

  • 放入My.Settings.Save()FormClosing 事件处理程序

  • 运行应用程序,在文本框中写一些东西,关闭表单(通过 X,而不是通过停止调试),然后立即再次打开应用程序(运行它)

于 2020-09-26T12:44:17.943 回答