The Form has a DataGridView (it shows one line) and a WebBrowser .
The Form on the Event keyDown has a handler that is triggered by pressing F2 , which writes the word to a specific cell. The same handler is bound to a DataGridView .
private: System::Void CSV_WViewForm_KeyDown( System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) { if (e->KeyCode == Keys::F2) /*Do something*/; } It is necessary that pressing F2 works always and immediately (the first time). For this, I used the property KeyPreview = false; (I tried to set it to true - it did not help).
protected: virtual bool ProcessCmdKey(Message% msg, Keys keyData) override { if (keyData == Keys::F2) { this->dataGridView1->Focus(); return Form::ProcessCmdKey(msg, keyData); } return Form::ProcessCmdKey(msg, keyData); } But when Focus is in WebBrowser , F2 does not always work (sometimes you have to press F2 twice). How to win it?
Windows Forms project (C ++, Visual Studio 2015)