Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using web browser inside winform.
seems that when left click the web browser it takes the focuse from the form, and i can't get the focus back to the form. i've tried: this.Focuse(), this.Acticate(), even tried to set the focus to any label or textbox in the form, but nothing helped. i can't release the focus from the browser..
Posted

Hello

I tried this way and I know it's not flawless but it works:

C#
this.MyBrowser.Visible = false;
this.Focus();
this.MyBrowser.Visible = true;


A better way is:
Use a Panel as the parent of the WebBrowser:
C#
MyPanel.Enabled = false;
this.Focus();
MyPanel.Enabled = true;
 
Share this answer
 
v5
Comments
itsika 13-Mar-12 12:57pm    
but where to put it? can you give simple example? i didn't found any "WebBrowser_Click" event, the focus changed while user left click the browser, so to implement what you wrote i need to catch the event that user clicked the webbrowser.. (also it doesn't automatically re-focuse to the form while i'm clicking the form)
Shahin Khorshidnia 13-Mar-12 14:39pm    
you can use this code when you want to get the focus back.

you said: "i've tried: this.Focuse(), this.Acticate(), even tried to set the focus to any label or textbox in the form, but nothing helped. i can't release the focus from the browser.."
You tried X, ok? Try my code instead of X! is it clear?
itsika 14-Mar-12 5:24am    
yes, don't need to get mad :) seems that from the first place i didn't put the "this.focus()" in the right place so he had never called it. but even when i put it in the right place it doesn't worked, your solution works! probably when the active control is disabled or set as not visible so the focus can redirected to something else, and probably it's make sense..
Shahin Khorshidnia 14-Mar-12 16:37pm    
I didn't get mad my friend, trust me ;)
Thank you for accepting
myrowser.Parent = this;

will gives focus to form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900