Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how to disable webbrowser usage

Tags:

c#

winforms

I have a C# application that has a webbrowser and need to be able to completely disable it at times. What is the best method of doing this?

I was thinking about creating a transparent panel to put over the webbrowser when needed, but am not sure if this is the best approach. I also noticed that C# doesn't easily allow making a panel transparent.

Edit: To clarify what I mean by disable...I don't want to allow the user to be able to click or change\edit anything in the webbrowser.

like image 414
MD6380 Avatar asked Feb 26 '09 17:02

MD6380


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

Strangely the WebBrowser control doesn't have an Enabled property as you might expect it to. You can set the AllowNavigation property to false which will stop the user clicking on links.

Turns out it does have an Enabled property, inherited from Control. But you have to explicitly cast it to Control to access it:

((Control)webBrowser1).Enabled = false;

You should be aware though that setting Enabled completely disables any user interaction with the WebBrowser control. That includes the scroll bar, so once you set Enabled to false the user can't even scroll the web page in the control.

If that was more than you wanted then setting the AllowNavigation property to false will stop the user clicking on links but still allow them to scroll the page. You'd need to check though that it also stops Javascript onclick events from firing.

If you wanted to stop any events from firing in the page you could probably achieve that will some DOM work from the WebForms code into the WebBrowser control. You also probably need to start disabling input controls within the WebBrowser. It all depends how disabled you want it.

like image 124
andynormancx Avatar answered Sep 23 '22 22:09

andynormancx