被解雇时我有一个事件:

htmlView.DocumentText = contentArea.Text;

问题是此事件被触发了很多,我得到了令人讨厌的IE“点击噪音”。我见过一个解决方案HowTo Disable WebBrowser 'Click Sound' in your app only和另一个解决方案,但是我对C Sharp还是很陌生(仅使用了几个小时),并且不确定:
private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
private const int SET_FEATURE_ON_THREAD = 0x00000001;
private const int SET_FEATURE_ON_PROCESS = 0x00000002;
private const int SET_FEATURE_IN_REGISTRY = 0x00000004;
private const int SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008;
private const int SET_FEATURE_ON_THREAD_INTRANET = 0x00000010;
private const int SET_FEATURE_ON_THREAD_TRUSTED = 0x00000020;
private const int SET_FEATURE_ON_THREAD_INTERNET = 0x00000040;
private const int SET_FEATURE_ON_THREAD_RESTRICTED = 0x00000080;

...

[DllImport("urlmon.dll")]
[PreserveSig]
[return:MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(
    int FeatureEntry,
    [MarshalAs(UnmanagedType.U4)] int dwFlags,
    bool fEnable);

...手段。我将代码放在哪里?抱歉,我是C Sharp和Visual Studio的新手,很感谢新手可以理解的帮助。

谢谢!

最佳答案

您可以将其放在静态类中,并公开CoInternetSetFeatureEnabled方法,或者添加一个附加的bridge方法,该方法在从更可用的形式转换参数之后,如有必要,可以调用它。例如,在第一种情况下,它将是:

public static class UnmanagedCode
{
    private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
    //etc...

    [DllImport("urlmon.dll")]
    [PreserveSig]
    [return:MarshalAs(UnmanagedType.Error)]
    public static extern int CoInternetSetFeatureEnabled(
        int FeatureEntry,
        [MarshalAs(UnmanagedType.U4)] int dwFlags,
        bool fEnable);
}

关于c# - 如何使用C Sharp中的WebBrowser元素禁用“单击声音”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1720902/

10-10 13:31