0

I'm using WebBrowser control to show/edit body content from an email. All of this I did in an UserControl.

I was looking for on events of designer and WebBrowser doesn't have WebBrowser.TextChange method. I'd like write on it a method to detect the number of characters that user's typing. (ONLY TEXT, ignore images, etc...)

1 Answers1

1

System.Windows.Controls.WebBrowser has not text property, so it has not TextChanged event. If you really want to do this, you may try KeyDwon or KeyUp event to achieve it.

The comment can't paste long code , so i add the code here.

<UserControl x:Class="WpfApplication2.UserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <WebBrowser Name="wb" TextInput="wb_TextInput" KeyDown="wb_KeyDown" Visibility="Visible"/>
</Grid>
</UserControl>


public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
        //wb.Navigate("http://www.baidu.com");
        wb.Navigate("http://www.bing.com");
    }

    private void wb_TextInput(object sender, TextCompositionEventArgs e)
    {
        //not work
    }

    private void wb_KeyDown(object sender, KeyEventArgs e)
    {
        MessageBox.Show(e.Key.ToString());
        e.Handled = false;
    }
}
chengzi
  • 170
  • 2
  • 10