打开对话框以显示文件并使用复选框保存它 vb.net

opendialog to show a file and save it with checkbox vb.net

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

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

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

这是我当前的代码:

    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

我已经在网上搜索过了,但真的找不到要做什么?

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

跟我一起过一遍:

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

  • 单击文本框:

  • 在顶部的属性网格中单击 (应用程序设置),然后单击 属性 绑定 旁边的 3 个点.滚动到 文本。下拉设置并选择底部的 New

  • 将其命名为 ChosenDatabasePath 或类似的有用且具有描述性的名称

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

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

  • 在 属性 网格中切换到事件时,单击窗体背景上的任意位置,找到 FormClosing 并双击它

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

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