Some detail settings for WebBrowser in C #

Source: Internet
Author: User

In WinForm, there is a control that can display the contents of the HTML, which is WebBrowser, setting its Documentext property to the contents of the HTML.

When using WebBrowser to do the UI, we sometimes do not want the link inside the user click, more do not want to pop up annoying script error prompt box, do not want users to point out the right-click IE menu, to do these, in fact, are very easy to ...

Set WebBrowser
Webbrowser1.scripterrorssuppressed = true; Disable error scripting Tips
webbrowser1.iswebbrowsercontextmenuenabled = false; Disabling the right-click menu
webbrowser1.webbrowsershortcutsenabled = false; Disable shortcut keys
Webbrowser1.allowwebbrowserdrop = false;//No drag
webbrowser1.scrollbarsenabled = false;//Forbidden scroll bar

Disable error scripting Tip : Set the scripterrorssuppressed of the WebBrowser control to True
Disable the right-click menu : Set WebBrowser iswebbrowsercontextmenuenabled to False
Disable shortcut keys: Set WebBrowser's webbrowsershortcutsenabled to False
Disable Hyperlinks : There are two kinds of hyperlinks, one is the current window direct, one is open in a new window
Of course the window turns directly: Set the allownavigation of WebBrowser to False
Disable new window open, need to handle WebBrowser NewWindow event

private void Webbrowser1_newwindow (object sender, CancelEventArgs e)
{
E.cancel = true;
}

Finish the work above, the basic is finished, and the last point to note, that is  drag-and-drop  . Remember to set  WebBrowser   AllowWebBrowserDrop  as  false 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.