我創建的擴展方法,以防止AxAcroPDF竊取代碼,應當這樣使用:
PDF_Reader.SuspendStealFocus()
PDF_Reader.Loadfile(TXT_BrowsePDF.Text)
原始C#源文件可以發現here。我用.net反射將其轉換爲VB.NET(僅在測試的WinForms,它將數據存儲在PDF_Reader.Tag):
<Extension> _
Friend Class AxAcroPDFFocusExtensions
<Extension> _
Public Shared Sub SuspendStealFocus(ByVal pdfControl As AxAcroPDF)
pdfControl.SuspendStealFocus(250)
End Sub
<Extension> _
Public Shared Sub SuspendStealFocus(ByVal pdfControl As AxAcroPDF, ByVal timeoutInMilliSeconds As Integer)
pdfControl.Enabled = False;
Dim t As New Timer
t.Interval = timeoutInMilliSeconds
AddHandler t.Tick, New EventHandler(AddressOf AxAcroPDFFocusExtensions.t_Tick)
t.Start
pdfControl.Tag = Guid.NewGuid
t.Tag = New TimerTag(pdfControl, pdfControl.Tag)
End Sub
<Extension> _
Public Shared Sub SuspendStealFocus(ByVal pdfControl As AxAcroPDF, ByVal timeSpan As TimeSpan)
pdfControl.SuspendStealFocus(CInt(timeSpan.TotalMilliseconds))
End Sub
Private Shared Sub t_Tick(ByVal sender As Object, ByVal e As EventArgs)
Dim timer As Timer = DirectCast(sender, Timer)
timer.Stop
timer.Dispose
Dim t As TimerTag = DirectCast(timer.Tag, TimerTag)
If Object.ReferenceEquals(t.Control.Tag, t.ControlTag) Then
t.Control.Enabled = True
End If
End Sub
<StructLayout(LayoutKind.Sequential)> _
Private Structure TimerTag
Public ControlTag As Object
Public Control As AxAcroPDF
Public Sub New(ByVal control As AxAcroPDF, ByVal controlTag As Object)
Me.Control = control
Me.ControlTag = controlTag
End Sub
End Structure
End Class
來源
2014-05-28 10:56:52
bvs