单击按钮时未触发事件

时间:2012-02-24 08:33:59

标签: vb.net events button

我正在编写一个程序,用于在按钮点击事件上使用FTP访问远程文件数据。在按钮单击事件的第一行中设置断点。该程序正在使用Windows应用程序 vb.net 2008.

如果我运行该应用程序,当我单击该按钮时,它不会触发该按钮的单击事件。帮我纠正。

这是我的代码:

Dim reqFTP As FtpWebRequest
Dim filepath As String
Dim filename As String
Dim filename1 As String
Dim ftpserverip As String
Dim ftpuserid As String
Dim ftpPassword As String
Try
    filename1 = TxtRemoteFile.Text
    filepath = TxtLocalFile.Text
    filename = Locfname.Text
    ftpserverip = TxtServerIP.Text
    ftpuserid = TxtUserName.Text
    ftpPassword = TxtPwd.Text

    Dim outputStream As FileStream = New FileStream((filepath + ("\\" + filename)), FileMode.Create)
    reqFTP = CType(FtpWebRequest.Create(New Uri(("ftp://" _
                        + (ftpserverip + ("/" + filename1))))), FtpWebRequest)
    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
    reqFTP.UseBinary = True
    reqFTP.Credentials = New NetworkCredential(ftpuserid, ftpPassword)
    Dim response As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse)

    Dim ftpStream As Stream = response.GetResponseStream
    Dim cl As Long = response.ContentLength
    Dim bufferSize As Integer = 2048
    Dim readCount As Integer
    Dim buffer() As Byte = New Byte((bufferSize) - 1) {}
    readCount = ftpStream.Read(buffer, 0, bufferSize)

    While (readCount > 0)
        outputStream.Write(buffer, 0, readCount)
        readCount = ftpStream.Read(buffer, 0, bufferSize)

    End While
    ftpStream.Close()

    outputStream.Close()
    response.Close()

Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try

在运行期间,当我单击按钮时,控件未输入到单击事件

1 个答案:

答案 0 :(得分:1)

可能是您的代码不在正确的处理程序中。

双击表单上的按钮,确保代码存在于此中。如果没有,只需简单地复制并粘贴即可。

希望这有帮助!