我创建了一个扩展方法来防止 AxAcroPDF 窃取代码,它应该像这样使用:
PDF_Reader.SuspendStealFocus()
PDF_Reader.Loadfile(TXT_BrowsePDF.Text)
可以在此处找到原始 C# 源文件。我使用 .NET Reflector 将其转换为 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