[RESOLVED] WebBrowser control - how to show Find window?-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] WebBrowser control - how to show Find window?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    569

    Resolved [RESOLVED] WebBrowser control - how to show Find window?

    Is there a method to show WebBrowser inbuilt find window', when user presses 'ascii' key ie. without first pressing <Ctrl> + <F> to pop up browser inbuilt find window?

    www.tektips.com shows one method, but this is somewhat limited - as, it does not;
    - highlight all match occurrences
    - does not scroll properly like inbuilt find window search does
    - uses different highlight color (blue) than inbuilt find window has set (yellow)

    www.tek-tips.com/viewthread.cfm?qid=1167680

    So basicly, need is to popup inbuilt find window automatically, when key in ascii range (0-9 and A-Z) is pressed.

    Tried to issue SendKeys "^F", but it 'somehow locks application' - hence does not work. Regardless of WebBrowser object has focus or not.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,732

    Re: WebBrowser control - how to show Find window?

    I didn't try SendKeys since you said it didn't work, but I did try KeyBd_Event API and would think SendInput API would work also.
    Code:
    Private Declare Sub keybd_event Lib "user32.dll" _
    (ByVal bVk As Byte, ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    Private Const KEYEVENTF_KEYUP As Long = &H2
    
    Private Sub Command1_Click()
        WebBrowser1.SetFocus
        keybd_event vbKeyControl, 0, 0, 0
        keybd_event vbKeyF, 0, 0, 0
        keybd_event vbKeyF, 0, KEYEVENTF_KEYUP, 0
        keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
    End Sub
    The above simply displays the "Find" window same as if you press Ctrl+F while the webbrowser had focus. I think that is what you were asking?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    569

    Re: WebBrowser control - how to show Find window?

    Thank you LaVolpe, that is exactly what i was asking. Submit Ctrl+F keypress to the Webbrowser control, so that Find window is displayed.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,884

    Re: [RESOLVED] WebBrowser control - how to show Find window?

    What about this?

    Code:
        WebBrowser1.ExecWB OLECMDID_FIND, OLECMDEXECOPT_PROMPTUSER

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2015
    Location
    Finland
    Posts
    569

    Re: [RESOLVED] WebBrowser control - how to show Find window?

    Thanks Dilettante.

    ExecWB method call, shows find window ok.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If Not bFindWindowDisplayed Then
            WebBrowser1.SetFocus
            WebBrowser1.ExecWB OLECMDID_FIND, OLECMDEXECOPT_PROMPTUSER  'Open WebBrowser Find dialog.
            bFindWindowDisplayed = True
            keybd_event KeyCode, 0, 0, 0  'Send pressed key char code to the Find dialog.
            keybd_event KeyCode, 0, KEYEVENTF_KEYUP, 0
        End If
    End Sub
    Alternative method using keybd_event API.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If Not bFindWindowDisplayed Then
            WebBrowser1.SetFocus
            'Send Ctrl+F to the WebBrowser control -> opens WebBrowser Find dialog.
            keybd_event vbKeyControl, 0, 0, 0 'Ctrl key down
            keybd_event vbKeyF, 0, 0, 0 'F key down
            keybd_event vbKeyF, 0, KEYEVENTF_KEYUP, 0 'F key up
            keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0 'Ctrl key up
            bFindWindowDisplayed = True
            keybd_event KeyCode, 0, 0, 0  'Send pressed key char code to the Find dialog.
            keybd_event KeyCode, 0, KEYEVENTF_KEYUP, 0
        End If
    End Sub

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

Survey posted by VBForums.