PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED POORLY] Setting a PDF embedded inside a WebBrowser as the ActiveControl-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED POORLY] Setting a PDF embedded inside a WebBrowser as the ActiveControl

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    Resolved [RESOLVED POORLY] Setting a PDF embedded inside a WebBrowser as the ActiveControl

    Hi all,

    I have a Windows Form with a TabControl, one of the tabs is named Tab_Help, and it contains a WebBrowser control which navigates to a PDF file that I generate.

    My goal is to have the the PDF embedded inside the WebBrowser gain focus when the user selects the Help Tab. As it stands now, users need to click the PDF to begin scrolling through it, and I'd like to make it easier by shifting focus to the PDF the moment the Help tab is selected.

    I set the WebBrowser to load the PDF on Form1 load, and aside from the fact that users need to click it before they can scroll through it, the PDF itself works perfectly.

    vb.net Code:
    1. Private Sub Form1.Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    2.     WebBrowser1.Navigate("C:\temp\pdftest.pdf#toolbar=0") ' Works perfectly
    3. End Sub
    4.  
    5. Private Sub TabControl_SelectedIndexChanged() Handles TabControl.SelectedIndexChanged
    6.     If TabControl.SelectedIndex = TabControl.TabPages.IndexOf(Tab_Log) Then
    7.         ActiveControl = Textbox_Log ' This works perfectly, allows scrolling immediately
    8.     ElseIf TabControl.SelectedIndex = TabControl.TabPages.IndexOf(Tab_Help) Then
    9.         ActiveControl = WebBrowser1 ' Doesn't work
    10.         'WebBrowser1.Focus() ' Also doesn't work
    11.         'WebBrowser1.Document.Focus() ' Also doesn't work
    12.     End If
    13. End Sub

    Any suggestions?
    Last edited by RichardG; Jul 5th, 2017 at 01:15 PM. Reason: Kinda resolved, I guess

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    Re: Setting a PDF embedded inside a WebBrowser as the ActiveControl

    Okay I have a solution, but it's pretty ugly... I'd certainly welcome any advice on how I could do this in a less..... stupid... way....

    So the first thing I did was add an invisible button in my Help Tab.
    Then I set the TabIndex of the invisible button to 9, and set the TabIndex of the WebBrowser to 10.
    (Selecting 9 and 10 is arbitrary, but high numbers gives me room to add several more controls to the help tab in the future without messing things up.)

    When the user selects the help tab, I set focus on the invisible button, then Tab into the WebControl, then Shift-Tab back to my button, then Tab into the Webcontrol again.

    I needed to do it this way because simply selecting the button and tabbing once into the Webcontrol worked every other time. If I had to guess why, i'd say the WebControl has it's own internal tabbing system that would not reset.

    Here's the new code in all it's ugly glory:

    vb.net Code:
    1. Private Sub Form1.Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    2.     WebBrowser1.Navigate("C:\temp\pdftest.pdf#toolbar=0") ' Works perfectly
    3. End Sub
    4.  
    5. Private Sub TabControl_SelectedIndexChanged() Handles TabControl.SelectedIndexChanged
    6.     If TabControl.SelectedIndex = TabControl.TabPages.IndexOf(Tab_Log) Then
    7.         ActiveControl = Textbox_Log ' This works perfectly, allows scrolling immediately
    8.     ElseIf TabControl.SelectedIndex = TabControl.TabPages.IndexOf(Tab_Help) Then
    9.         Button_WebControl_Focus_Helper.Focus()
    10.         SendKeys.Send("{TAB}") ' Tab into the Webbrowser once
    11.         SendKeys.Send("+{TAB}") ' +{TAB} is Shift-Tab (back to the invisible button)
    12.         SendKeys.Send("{TAB}") ' Tab into the Webbrowser again
    13.     End If
    14. End Sub
    Last edited by RichardG; Jul 5th, 2017 at 12:44 PM. Reason: Found a slightly less stupid method

  3. #3
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,126

    Re: Setting a PDF embedded inside a WebBrowser as the ActiveControl

    Hi,

    I think it's..

    Code:
    'label1.Caption ist you Pdf File and Path
    WebBrowser1.Navigate "" & Label1.Caption
    regards
    Chris

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    Re: Setting a PDF embedded inside a WebBrowser as the ActiveControl

    WebBrowser.Navigate("C:\temp\pdftest.pdf#toolbar=0") works perfectly, my issue was regarding difficulties focusing the WebBrowser component so that users would be able to scroll through the PDF without clicking the WebBrowser control first.

  5. #5
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,126

    Re: [RESOLVED POORLY] Setting a PDF embedded inside a WebBrowser as the ActiveControl

    Oh sorry,

    did not see that

    try this...
    Code:
    With Form1.WebBrowser1.Document.All("Text1.Text")' or your Button
       .focus()
       .RaiseEvent("Click")
    End With
    regards
    Chris

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    25

    Re: [RESOLVED POORLY] Setting a PDF embedded inside a WebBrowser as the ActiveControl

    Thanks for trying, but I get a NullReferenceException on Me.WebBrowser1.Document.All("Text1.Text") no matter what I put inside All("")

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width