没有使用AxAcroPdf阅读器关闭表单

时间:2017-02-17 15:13:49

标签: vb.net winforms

我有一个带有pdf阅读器的winform控制AxAcroPdf阅读器,事情是在我将pdf文件转发到控件之后,当我想关闭表单时,需要大约30秒来完成事件,我一直在搜索couse,事件将Dispose()事件放到控件中,但是无法在apropiate时间关闭表单,总是需要大约30秒才能关闭表单...

以下是我拥有控件的表单中的代码......

Private Sub cargarPdf(ByRef nombre_Archivo)
        Try
            AxAcroPDF1.Visible = True
            Dim con As SqlConnection = New SqlConnection(cadena)
            Dim comando As SqlCommand = con.CreateCommand()
            comando.CommandText = "SELECT file_stream FROM dbo.Tabla_archivos where name = @name"
            comando.Parameters.AddWithValue("@name", nombre_Archivo)
            con.Open()
            Dim dr As SqlDataReader = comando.ExecuteReader(CommandBehavior.CloseConnection)
            dr.Read()
            Dim bufferSize As Integer = Convert.ToInt32(dr.GetBytes(0, 0, Nothing, 0, 0))
            datos = New Byte(bufferSize - 1) {}
            dr.GetBytes(0, 0, datos, 0, bufferSize)
            dr.Close()
            WriteBinaryFile("C:\Cobit\" + nombre_Archivo, datos)
            AxAcroPDF1.src = "C:\Cobit\" + nombre_Archivo
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

这是基本形式的代码......

Private Sub BtnCerrar_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If NombreLbl.Text = "Vista Archivos de evidencia" Then
            Try
                Frm_vista_archivos_evidencia.AxAcroPDF1.Dispose()

            Catch ex As Exception
            End Try
        End If
        Me.Close()
    End Sub

具有控件的表单是Frm_base

的派生形式

1 个答案:

答案 0 :(得分:0)

最新版本的Acrobat Reader中存在一个错误,当控件处于Form关闭状态时会导致延迟。似乎有一些打开PDF文档的链接。您可以通过将其src属性设置为不存在的PDF文件来强制控件关闭文档;将其设置为Nothing或空字符串无效。对于这种文档关闭技术的信誉归功于" kenstanley2014"在Adobe论坛发帖How do I clear the file from AxAcroPDF object?。如果您先关闭文件然后关闭表单,它将很快关闭。但是,我发现这必须通过两个单独的UI交互,因为将它们放在同一个方法中会失败,就像设置src属性并使用计时器来触发close命令一样。

无论出于何种原因,我决定看看隐藏表格是否会产生影响。它确实!,并且根本不需要设置src属性。只需在FormClosed事件处理程序中将Form的Visible属性设置为False即可。

Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
    Me.Visible = False
End Sub

我不知道为什么会这样,你的经历会有所不同。 使用Adobe Acrobat Reader DC在Windows 10 64位上进行测试,版本。 15.023.20056.16516。