Note that there are some explanatory texts on larger screens.

plurals
  1. POHowTo Disable WebBrowser 'Click Sound' in your app only
    primarykey
    data
    text
    <p>The 'click sound' in question is actually a system wide preference, so I only want it to be disabled when my application has focus and then re-enable when the application closes/loses focus.</p> <p>Originally, I wanted to ask this question here on stackoverflow, but I was not yet in the beta. So, after googling for the answer and finding only a little bit of information on it I came up with the following and decided to post it here now that I'm in the beta.</p> <pre><code>using System; using Microsoft.Win32; namespace HowTo { class WebClickSound { /// &lt;summary&gt; /// Enables or disables the web browser navigating click sound. /// &lt;/summary&gt; public static bool Enabled { get { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current"); string keyValue = (string)key.GetValue(null); return String.IsNullOrEmpty(keyValue) == false &amp;&amp; keyValue != "\"\""; } set { string keyValue; if (value) { keyValue = "%SystemRoot%\\Media\\"; if (Environment.OSVersion.Version.Major == 5 &amp;&amp; Environment.OSVersion.Version.Minor &gt; 0) { // XP keyValue += "Windows XP Start.wav"; } else if (Environment.OSVersion.Version.Major == 6) { // Vista keyValue += "Windows Navigation Start.wav"; } else { // Don't know the file name so I won't be able to re-enable it return; } } else { keyValue = "\"\""; } // Open and set the key that points to the file RegistryKey key = Registry.CurrentUser.OpenSubKey(@"AppEvents\Schemes\Apps\Explorer\Navigating\.Current", true); key.SetValue(null, keyValue, RegistryValueKind.ExpandString); isEnabled = value; } } } } </code></pre> <p>Then in the main form we use the above code in these 3 events: </p> <ul> <li>Activated </li> <li>Deactivated </li> <li><p>FormClosing</p> <pre><code>private void Form1_Activated(object sender, EventArgs e) { // Disable the sound when the program has focus WebClickSound.Enabled = false; } private void Form1_Deactivate(object sender, EventArgs e) { // Enable the sound when the program is out of focus WebClickSound.Enabled = true; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // Enable the sound on app exit WebClickSound.Enabled = true; } </code></pre></li> </ul> <p>The one problem I see currently is if the program crashes they won't have the click sound until they re-launch my application, but they wouldn't know to do that.</p> <p>What do you guys think? Is this a good solution? What improvements can be made?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload