Send mouseclick event to webbrowser control RRS feed

  • Question

  • How do I send a programmatical (non-physical) mouse click to a web browser control at specified coordinates?

     Is it possible to hide the control while performing these clicks?

    Friday, December 23, 2005 1:35 PM

All replies

  • First before I answer that question, if you are trying to automate a browser (IE) there may be a better way to do that. Consider this article (http://msdn.microsoft.com/msdnmag/issues/05/10/TestRun/default.aspx) before getting too complicated. What you want to do can be done, however requires interop. If that will not work, you will need to use some interop with the user32.dll. First thing is first, you need a handle to your window. Using that handle (IntPtr) use WindowProc to send the button click message. Read about it here. This is somewhat advanced. That is why I recommend the first option.


    As to your second question, you can do it while the window is hidden if you do it right. What you want to do is set the window's style (again with interop) to SW_HIDE.

    Friday, December 23, 2005 3:07 PM
  • Thanks for your reply. I had a look at those links and they seemed quite complicated for what I'm trying to accomplish.

    I have a basic Windows form in Visual C# 2005 Express. On that I have a WebBrowser control which starts of at a URL. I need to send a mouseclick event to the control at specified coordinates of the web page.

    Ideally I would like to just change the URL but that isn't possible for web pages I'm working with (java, flash, cookies or postdata that I have no clue on how to deal with).

    Is there a simple way, like a function that I can use to do this? And like I've requested above, is it aslo possible to do it when the WebBrowser control is hidden?
    Friday, December 23, 2005 5:13 PM