Imports System.Runtime.InteropServices
Public Class Form7
Private _appPath As String
Private Property AppPath(ByVal p1 As String) As String
Get
Return _appPath
End Get
Set(ByVal value As String)
_appPath = value
End Set
End Property
Private Const WM_DEVICECHANGE As Integer = &H219
Private Const DBT_DEVICEARRIVAL As Integer = &H8000
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_DEVICECHANGE Then
If m.WParam.ToInt32() = DBT_DEVICEARRIVAL Then
MessageBox.Show("Connect Flash Drive Success")
End If
End If
MyBase.WndProc(m)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strPath As String = AppPath(Environment.CurrentDirectory)
Dim OpenFile As New OpenFileDialog()
OpenFile.InitialDirectory = strPath
OpenFile.FileName = ""
OpenFile.Filter = "Text files (*.txt)|*.txt"
Dim Res As System.Windows.Forms.DialogResult = OpenFile.ShowDialog()
If Res = System.Windows.Forms.DialogResult.Cancel Then Return
txtFile.Text = OpenFile.FileName
End Sub
End Class
Dim strPath As String = AppPath(Environment.CurrentDirectory)