Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ChromiumWebBrowser: Prevent control from stealing focus

I'm making a program that has a Form with a ChromiumWebBrowser in it. The navigation is done automatically. When webbrowser complete it's task, I'll dispose it, create a new webbrowser, add it to form, and load a new address.

But, when the new webbrowser was created and added to form, the program jumps in front of what ever other program is in the top with focus. Example: I start my program, press the button to start its task, open notepad to type some text and my program jumps in front of it when navigating to a new site.

Even when the window is minimized, it still steals focus from other open programs.

How do I prevent it stealing focus after it is created?

like image 412
Minh Giang Avatar asked Dec 01 '25 09:12

Minh Giang


1 Answers

As @amaitland said, this looks like a bug.

Workarounds I've used are:

1) disable the browser. This will prevent the browser from receiving mouse/keyboard input, but it won't "grey-out" the control.

Browser1 = New CefSharp.WinForms.ChromiumWebBrowser(url)
Browser1.Enabled = False

2) Pass a callback .net function for when the page loads where you simply put the focus back to winforms by focusing on a label of your choice.

Label1.Focus()
like image 195
CrazyTim Avatar answered Dec 03 '25 00:12

CrazyTim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!