+1  A: 

Without getting into whether your approach is correct. (and I suspect it is not).

I would gamble that You have a race condition. Which mean that the browser control needs more time to load and respond to events than you are letting it.

So when you do Message.Show, suddenly the thread that you send the events is blocked and it is letting the browser control complete intializing or something else.

It is hard to know from your question whether you are running on Mobile, or regular desktop because there are better approaches to deal with touch. Look at Window7 Api for multi Touch or WPF 4.0 (which is shared by Surface Touch SDK aswell).

Hope that helps. Ariel

ArielBH
A: 

It may be that the browser control is still loading a document and the message box gives it enough time to finish. If so, wait until the browser's IsBusy property is false or use the DocumentCompleted event.

Adam Ruth
A: 

I do not know, but in general in my experience it is a bad idea to try to change the focus programmatically like this, you always end up on a bug hunt. There are lots of ways to get windows to scroll though, so maybe you should try something else? For example JavaScript in the web browser can scroll the window effectively.

1800 INFORMATION
A: 

I suspect that you have a race here what gets done first. Focusing the control might not be instantaneous and the keystroke you send went elsewhere, whereas after closing the message box the browser control is already focused and gets its keystroke.

Also, to quote a note from MSDN about Control.Focus():

Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.

So using one of those might be better than using Focus().

Joey
Shouldnt the Application.DoEvents() take care of that? I mean, i got that in between so it got time to actually focus on the control...
Folkert
+1  A: 

To me this looks like the wrong way to be going about this.

Try something along the lines of this C++ sample or this C# sample.

At least be explicit about the HWND you are sending the message to if you are going to be simulating key presses.

Sam Saffron
That c# sample really helped a lot! Thank you!
Folkert