event not picked up by form
-
my program is very simple. When you press spacebar it shows next file in directory in webBroser control that fills my whole form. The problem is when I click on the web form or the menu or another window and then comeback and hit spacebar, it doesn't work. I was thinking it lost focus, but after I set focus back to the form it still didn't pick up the event. Also, how would I set my Form Width to that of the webpage or picture being displayed in the webBroswer control? Thanks
-
my program is very simple. When you press spacebar it shows next file in directory in webBroser control that fills my whole form. The problem is when I click on the web form or the menu or another window and then comeback and hit spacebar, it doesn't work. I was thinking it lost focus, but after I set focus back to the form it still didn't pick up the event. Also, how would I set my Form Width to that of the webpage or picture being displayed in the webBroswer control? Thanks
The WebBrowser control is an ActiveX control and dispatches messages in its own thread, i.e. .NET will not respond to notification messages for that ActiveX control. If you set the focus back to the
Form
by clicking in aTextBox
or aButton
or something, then it actually has the focus and will process the key down and up messages. To combat this, setForm.KeyPreview
totrue
. This will handle certain notification messages (which the .NET FCL assemblies translate to events) before the control with the focus. This will still not help when the WebBrowser control has the focus. As far as your last question goes, this really isn't possible. The width of a page or an image displayed in the WebBrowser control doesn't set the size of the WebBrowser control. Rather, the WebBrowser control sets the size. Now, script in the page can set the size of the WebBrowser control (depending on security settings). You can declare theIDocHostUIHandler
and override theResizeBorder
in order for yourForm
(the hosting control) to resize itself if script resizes the Window. See the article Using MSHTML Advanced Hosting Interfaces[^] for more details on this.Microsoft MVP, Visual C# My Articles
-
The WebBrowser control is an ActiveX control and dispatches messages in its own thread, i.e. .NET will not respond to notification messages for that ActiveX control. If you set the focus back to the
Form
by clicking in aTextBox
or aButton
or something, then it actually has the focus and will process the key down and up messages. To combat this, setForm.KeyPreview
totrue
. This will handle certain notification messages (which the .NET FCL assemblies translate to events) before the control with the focus. This will still not help when the WebBrowser control has the focus. As far as your last question goes, this really isn't possible. The width of a page or an image displayed in the WebBrowser control doesn't set the size of the WebBrowser control. Rather, the WebBrowser control sets the size. Now, script in the page can set the size of the WebBrowser control (depending on security settings). You can declare theIDocHostUIHandler
and override theResizeBorder
in order for yourForm
(the hosting control) to resize itself if script resizes the Window. See the article Using MSHTML Advanced Hosting Interfaces[^] for more details on this.Microsoft MVP, Visual C# My Articles