form1.vb

来自「Microsoft Mobile Development Handbook的代码」· VB 代码 · 共 45 行

VB
45
字号
Imports System.IO
Imports System.Reflection

Public Class Form1

    Private configSettings As Dictionary(Of String, String)
    Private WithEvents tmr As Timer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        configSettings = New Dictionary(Of String, String)()

        tmr = New Timer()
        tmr.Interval = 10
        tmr.Enabled = True
    End Sub

    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles tmr.Tick
        CType(sender, Timer).Enabled = False
        DoLogin()
    End Sub

    Private Sub DoLogin()
        ' Get the user to login
        Using frm As LoginForm = New LoginForm(configSettings)
            frm.ShowDialog()
        End Using

        ' Set connectionstring to database
        Me.MessagesTableAdapter.Connection.ConnectionString = _
                "Data Source =""" + GetApplicationDirectory() + "\AppDatabase.sdf""; password=" _
                + configSettings("DatabasePassword")

        If AppDatabaseDataSetUtil.DesignerUtil.IsRunTime() Then
            ' TODO: Delete this line of code to remove the default AutoFill for 'appDatabaseDataSet.Messages'.
            Me.messagesTableAdapter.Fill(Me.appDatabaseDataSet.Messages)
        End If
    End Sub


    Private Function GetApplicationDirectory() As String
        Return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules(0).FullyQualifiedName)
    End Function

End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?