Reputation: 1039
In my winform application I have webbrowser control. I need to handle backspace keypress to navigatу to another page when this button was pressed. I found PreviewKeyDown event of the webbrowser control.
I used this event but now I need check if backspace button was pressed inside of the textbox or some textarea. User need type in that controls. Now when he try delete some wrong character my application is catching previewkeydown event and navigate user to other page.
How I could check if user press backspace when he was in textbox?
Upvotes: 2
Views: 1942
Reputation: 129
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("google.com");
webBrowser1.PreviewKeyDown += new PreviewKeyDownEventHandler(webBrowser1_PreviewKeyDown);
}
void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
string activeTag = webBrowser1.Document.ActiveElement.TagName.ToLower();
if (activeTag == "input" || activeTag == "textarea")
{ }
else
{ }
}
}
Upvotes: 1