How can you enable the find (inbuild) functionality in IE when you use WebBrowser control on windows form having shortcuts disabled.


 


Suppose you are creating a Windows Application and you have added WebBrowser control in it so that you can show a webpage. And for security purpose you have disabled shortcuts (like Ctrl+N and other keys) by using WebBrowser's WebBrowserShortcutsEnabled property. But now you need to have the search functionality enabled so that user can search his interesting text in the lengthy webpage.


 Below is the solution:



  • Add below code to PreviewKeyDown event of WebBrowser control



Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown

If e.Control = True Then  ' if control key is pressed

 If e.KeyValue = Keys.F Then  ' if keyboard key F is pressed
  e.IsInputKey = False  ' input key is not processed and pass this key to control to process
 Else
  e.IsInputKey = True  ' I have processed input key my self no need to send to the control now
 End If

Else

 e.IsInputKey = True ' I have processed input key my self no need to send to the control now

End If


 


The above code will only Ctrl + F to be processed and rest of all key hits will be ignored. This solved the issue Smile!!




Skip to main content