01.
Imports
System.Runtime.InteropServices
02.
Public
Class
Form7
03.
Private
_appPath
As
String
04.
05.
Private
Property
AppPath(
ByVal
p1
As
String
)
As
String
06.
Get
07.
Return
_appPath
08.
End
Get
09.
Set
(
ByVal
value
As
String
)
10.
_appPath = value
11.
End
Set
12.
End
Property
13.
Private
Const
WM_DEVICECHANGE
As
Integer
= &H219
14.
Private
Const
DBT_DEVICEARRIVAL
As
Integer
= &H8000
15.
Protected
Overrides
Sub
WndProc(
ByRef
m
As
Message)
16.
If
m.Msg = WM_DEVICECHANGE
Then
17.
If
m.WParam.ToInt32() = DBT_DEVICEARRIVAL
Then
18.
MessageBox.Show(
"Connect Flash Drive Success"
)
19.
End
If
20.
End
If
21.
MyBase
.WndProc(m)
22.
End
Sub
23.
24.
Private
Sub
Button1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
25.
Dim
strPath
As
String
= AppPath(Environment.CurrentDirectory)
26.
27.
Dim
OpenFile
As
New
OpenFileDialog()
28.
29.
OpenFile.InitialDirectory = strPath
30.
OpenFile.FileName =
""
31.
32.
OpenFile.Filter =
"Text files (*.txt)|*.txt"
33.
34.
35.
Dim
Res
As
System.Windows.Forms.DialogResult = OpenFile.ShowDialog()
36.
37.
If
Res = System.Windows.Forms.DialogResult.Cancel
Then
Return
38.
39.
40.
txtFile.Text = OpenFile.FileName
41.
42.
End
Sub
43.
End
Class