武汉理工大学《计算机网络》课程设计说明书
Case \ mnuRename_Click Case \ lvListView.View = lvwIcon Case \
lvListView.View = lvwSmallIcon Case \
lvListView.View = lvwList Case \
lvListView.View = lvwReport End Select End Sub
Private Sub mnuFileClose_Click() 'unload the form Unload Me End Sub
Public Function FormatFileSize(lFileSize As Long) As String On Error GoTo ERROR_HANDLER If lFileSize >= 1024 Then
FormatFileSize = Format$(CStr(lFileSize / 1024), \### ### KB\'CStr 转换为String类型 Else
FormatFileSize = CStr(lFileSize) & \ End If Exit Function ERROR_HANDLER:
Debug.Print Err.Number & \End Function
Private Sub tvTreeView_DragDrop(Source As Control, x As Single, y As Single) 'source只正在
10
武汉理工大学《计算机网络》课程设计说明书
被拖动的控件,x,y指鼠标指针在目标对象中的坐标值 If Source = imgSplitter Then SizeControls x End If End Sub
Private Sub AddFileToListView(oFtpFile As CFtpFile) Dim intIcon As Integer Dim strFileName As String strFileName = oFtpFile.FileName intIcon = GetImageNumber(strFileName)
Set lvItem = lvListView.ListItems.Add(, strFileName, strFileName, intIcon, intIcon) lvItem.SubItems(1) = oFtpFile.FileSize lvItem.SubItems(2) = oFtpFile.LastWriteTime End Sub
Private Sub RefreshDirectory()
With tvTreeView.SelectedItem '从treeview中移除所有subfolders If .Children > 0 Then For i = 1 To .Children
tvTreeView.Nodes.Remove (.Child.Index) Next i End If
lvListView.ListItems.Clear ListFiles tvTreeView.SelectedItem End With End Sub
Private Sub EstablishConnection() Dim tvNode As Node Dim f As New frmConnect
f.Show vbModal '显示连接窗体的内容
11
武汉理工大学《计算机网络》课程设计说明书
If f.Action = comdOK Then '当按下OK时,清空treeview和listview的内容 tvTreeView.Nodes.Clear lvListView.ListItems.Clear With m_FtpConnection .FtpServer = f.URL .UserName = f.UserName .Password = f.Password
.PassiveMode = CBool(Check1.Value) 'call Connect method If .Connect Then Label1 = f.URL
'add root node to the treeview
Set tvNode = tvTreeView.Nodes.Add(, , , .CurrentDirectory, 1) tvNode.Key = .CurrentDirectory Set tvTreeView.SelectedItem = tvNode ListFiles tvNode, True End If '.Connect End With 'm_FtpConnection End If 'f.Action = comdOK End Sub
5.2.2 frmconnect窗体的部分代码
Public Property Get UserName() As String UserName = mvarUserName End Property
Public Property Get Password() As String Password = mvarPassword End Property
Public Property Get URL() As String URL = mvarURL
12
武汉理工大学《计算机网络》课程设计说明书
End Property
Private Sub chkAnonym_Click() If chkAnonym.Value Then txtUserName = \ txtPassword.PasswordChar = \ txtPassword = \ Frame3.Caption = \Else txtUserName = \
txtPassword.PasswordChar = \ txtPassword = \
Frame3.Caption = \End If End Sub
Private Sub cmdCancel_Click() mvarAction = comdCancel Unload Me End Sub
Private Sub cmdOK_Click() If Len(txtURL) = 0 Then
MsgBox \URL\ Exit Sub
Else mvarURL = LCase(txtURL.Text) End If
If Len(txtUserName.Text) = 0 Then mvarUserName = vbNullString
Else mvarUserName = txtUserName.Text End If
If Len(txtPassword.Text) = 0 Then
13
武汉理工大学《计算机网络》课程设计说明书
mvarPassword = vbNullString Else mvarPassword = txtPassword.Text End If
mvarAction = comdOK Unload Me End Sub
Public Property Let Action(ByVal vData As Command) mvarAction = vData End Property
Public Property Get Action() As Command
'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.Action Action = mvarAction End Property
5.2 运行结果
5.2.1 开始界面(见图一)
(图一)
14