如何禁用WPF WebBrowser控件的单击噪音?

时间:2021-03-13 19:43:13

I've got a simple little WPF app with a TextBox and a WebBrowser control. As I type into the TextBox the WebBrowser updates with its content.

我有一个简单的小WPF应用程序,带有TextBox和WebBrowser控件。当我输入TextBox时,WebBrowser会更新其内容。

But on each keystroke, when the WebBrowser updates, it makes a click sound. How can I disable the WebBrowser control's refresh click sound?

但是在每次击键时,当WebBrowser更新时,它会发出咔嗒声。如何禁用WebBrowser控件的刷新咔嗒声?

WPF TextBox and WebBrowser controls http://img411.imageshack.us/img411/2296/appbz9.jpg

WPF TextBox和WebBrowser控件http://img411.imageshack.us/img411/2296/appbz9.jpg

My XAML...

<TextBox Name="MyTextBox"
         ...
         TextChanged="MyTextBox_TextChanged"
         TextWrapping="Wrap"
         AcceptsReturn="True"
         VerticalScrollBarVisibility="Visible" />
<WebBrowser Name="MyWebBrowser" ... />

My Visual Basic code...

我的Visual Basic代码......

Private Sub MyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
    If Not MyTextBox.Text = String.Empty Then
        MyWebBrowser.NavigateToString(MyTextBox.Text)
    Else
        MyWebBrowser.Source = Nothing
    End If
End Sub

2 个解决方案

#1


2  

That click is becouse of the navigation, doing that without it should not appear.

那个点击是因为导航,没有它就不应该出现。

I would introduce a div tag of mine in an empty HTML loaded in the webbrowser and in the moment of updating I would introduce the text of the textbox in the innerHTML property of the div. Without navigation.

我将在webbrowser中加载一个空的HTML中引入我的div标签,在更新的那一刻,我将在div的innerHTML属性中引入文本框的文本。没有导航。

Visual Basic code...

Visual Basic代码......

Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    MyWebBrowser.NavigateToString("<html><body><div id=""MyDiv""></div></body><html>")
End Sub

Private Sub MyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
    MyWebBrowser.Document.GetElementById("MyDiv").InnerHtml = MyTextBox.Text
End Sub

#2


2  

Well it's using IE7/8 container if I'm not mistaken so it may need to be done through Windows Sounds.

好吧,如果我没有弄错的话,它正在使用IE7 / 8容器,因此可能需要通过Windows Sounds来完成。

#1


2  

That click is becouse of the navigation, doing that without it should not appear.

那个点击是因为导航,没有它就不应该出现。

I would introduce a div tag of mine in an empty HTML loaded in the webbrowser and in the moment of updating I would introduce the text of the textbox in the innerHTML property of the div. Without navigation.

我将在webbrowser中加载一个空的HTML中引入我的div标签,在更新的那一刻,我将在div的innerHTML属性中引入文本框的文本。没有导航。

Visual Basic code...

Visual Basic代码......

Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    MyWebBrowser.NavigateToString("<html><body><div id=""MyDiv""></div></body><html>")
End Sub

Private Sub MyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs)
    MyWebBrowser.Document.GetElementById("MyDiv").InnerHtml = MyTextBox.Text
End Sub

#2


2  

Well it's using IE7/8 container if I'm not mistaken so it may need to be done through Windows Sounds.

好吧,如果我没有弄错的话,它正在使用IE7 / 8容器,因此可能需要通过Windows Sounds来完成。