65.9K
CodeProject is changing. Read more.
Home

Disable 'click' sound when accesing WebBrower control

Mar 24, 2010

CPOL
viewsIcon

24231

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.