Click here to Skip to main content
11,645,893 members (77,745 online)
Click here to Skip to main content

Disable 'click' sound when accesing WebBrower control

, 24 Mar 2010 CPOL 18.6K 3
Rate this:
Please Sign up or sign in to vote.
Depending on system preferences (in Control Panel/Sounds), the .NET WebBrowser control (just like Internet Explorer) may produce a click sound when changes are made programmatically to its DocumentText property, which is irritating to the user.There are two ways to avoid this:1. Use...
Depending on system preferences (in Control Panel/Sounds), the .NET WebBrowser control (just like Internet Explorer) may produce a click sound when changes are made programmatically to its DocumentText property, which is irritating to the user.

There are two ways to avoid this:

1. Use WebBrowser.Document.Write to change the browser document text.


So instead of this:

webBrowser1.DocumentText = "<h1>Hello, world!</h1>";

try this:

webBrowser1.Document.OpenNew(true);
webBrowser1.Document.Write("<h1>Hello, world!</h1>");

The side effect is that this method causes the application to steal focus from the active application whenever OpenNew is called.

2. Use the Document Object Model (DOM)'s InnerHTML property to change the text.

Me.WebSMSView.Document.DomDocument.Body.InnerHTML = text

This doesn't have any side effects as method 1, and is preferable. However, as DomDocument is an Object, late-binding need to be used for the above code to compile. in VB.NET, this can be done easily by turning Option Strict off. In C#, however, the above can only be done via reflection.

License

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

Share

About the Author

mdanh2002
Singapore Singapore
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 24 Mar 2010
Article Copyright 2010 by mdanh2002
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid