C # how to disable use of web browser

I have a C # application that has a web browser and should be able to completely disable it from time to time. What is the best way to do this?

I was thinking of creating a transparent panel to position the web browser when necessary, but I'm not sure if this is the best approach. I also noticed that C # does not make it easy to make a panel transparent.

Edit: Clarify what I mean by disabling ... I do not want the user to be able to click or change \ edit anything in a web browser.

+4
source share
5 answers

It is strange that the WebBrowser control does not have the Enabled property, as you might expect. You can set the AllowNavigation property to false, which prevents the user from clicking links.

It turns out that it has the Enabled property inherited from Control. But you must explicitly pass it to Control to access it:

((Control)webBrowser1).Enabled = false; 

You should be aware that this Enabled option completely disables any user interaction with the WebBrowser control. This includes a scroll bar, so once you set Enabled to false, the user cannot even scroll the web page in the control.

If this was more than you wanted, then setting the AllowNavigation property to false will cause the user to click on the links, but still allow them to scroll through the page. You should verify that this also stops Javascript onclick events from firing.

If you want to stop any events from firing on a page, you might achieve that some DOMs will work from WebForms code to a WebBrowser control. You probably also need to start disabling the input controls in WebBrowser. It all depends on how you want it.

+13
source

Based on your last comment, I would suggest that you use WinForms. (WPF makes it easy to skip transparent panels :-)) This means that you are using WebBrowser . Have you tried setting the Enabled property to false?

+3
source

When you say β€œdisconnect” it, what do you mean? If you set the Enabled property to false, it will be disabled, this works for all form controls. But if you need to, you can adjust the transparency of the panel by setting it to BackColor.

UPDATE: Actually, you're right, this is a wrapper for an ActiveX control, so it is not a typical WinForms control. What you want is a transparent paenl solution. This Toby guy has a solution on his blog:

http://saftsack.fs.uni-bayreuth.de/~dun3/archives/creating-a-transparent-panel-in-net/108.html

The main idea is to override this method in a panel class:

 protected override CreateParams CreateParams { get { CreateParams createParams = base.CreateParams; createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT return createParams; } } 
+1
source

Is it possible to remove a web browser from its parent control array?

0
source

In VB: DirectCast (WebBrowser1, Control) .Enabled = False

0
source

All Articles