我有一个winform,在那里我加载一个PDF到AxAcroPDF。
看起来像这样
Public sub LoadSelectedPDF()
PDF_Reader.Loadfile(TXT_BrowsePDF.Text) 'PDF_Reader is my AxAcroPDF
TXT_Title.Focus()
End Sub现在,当我运行它时,我可以看到它将焦点放在另一个文本框上,但在加载PDF时它失去了焦点(以及用于放大PDF和所有淡入的小工具条)。就像它刚开始加载,继续到下一行,当它实际加载时,它会获得焦点。我如何告诉它等待完全加载,然后专注于另一个文本框?
发布于 2014-05-28 18:56:53
我创建了一个扩展方法来防止AxAcroPDF窃取代码,它应该这样使用:
PDF_Reader.SuspendStealFocus()
PDF_Reader.Loadfile(TXT_BrowsePDF.Text)可以在here中找到原始的C#源文件。我使用了.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发布于 2016-11-08 20:57:20
将AxAcroPDF放入面板中,然后:
Public sub LoadSelectedPDF()
PDF_Reader.Loadfile(TXT_BrowsePDF.Text) 'PDF_Reader is my AxAcroPDF
panel_pdf.Enabled = False
TXT_Title.Focus()
End Sub在TXT_Title enter事件中:
System.Threading.Thread.Sleep(500)
panel_pdf.Enabled = Truehttps://stackoverflow.com/questions/22661524
复制相似问题