Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / Windows Forms
Tip/Trick

Disable 'click' sound when accesing WebBrower control

Rate me:
Please Sign up or sign in to vote.
2.67/5 (3 votes)
24 Mar 2010CPOL 24.1K   4  
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:

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


try this:

VB
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.

VB
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)


Written By
Technical Writer
Singapore Singapore
Since 2008, ToughDev has been publishing technical sharing articles on a wide range of topics from software development to electronics design. Our interests include, but are not limited to, Android/iOS programming, VoIP products, embedded design using Arduino/PIC microcontrollers, reverse-engineering, retro-computing, and many others. We also perform product reviews, both on new and vintage products, and share our findings with the community. In addition, our team also develops customized software/hardware solutions highly adapted to suit your needs. Contact us for more information.

Comments and Discussions

 
-- There are no messages in this forum --