C# – AcceptsReturn equivalent for WebBrowser .NET control

acceptbuttonbrowsercnettextarea

I have a Windows .NET application and one of the forms has a WebBrowser control, an OK button and a Cancel button.

The WebBrowser control hosts a TextArea html element, so I can write inside.

If the OK button is the form's AcceptButton (form.AcceptButton = btnOk) then when I press Enter the event is captured by the form, and no new line is added in my TextArea.

TextBox has a property AcceptsReturn that does exactly what I would need, but there is no similar property for WebBrowser control.

Any ideas on how to retain the Enter event for the TextArea if the form which hosts the WebBrowser has an AcceptButton?

Thanks.

alt text

Best Answer

I think you'd have to turn off the AcceptButton on your form while the TextArea has the focus in order for this to work. Your form has no way of "knowing" that it's not supposed to respond to the Enter key while something in particular is going on inside the WebBrowser control.