Note that there are some explanatory texts on larger screens.

plurals
  1. POTabPages :: Bring Tab To Front on KeyDown
    text
    copied!<p>I am working in Managed C++ via VS 2008. I am creating a Windows form app. The application contains 4 tabs. The user wants to be able to simply press a function key (in this case, F5, F7, F9 or F10) . . . to bring a tab page to the front.</p> <p>I know I have to capture the KeyDown event. That works fine. I know this because I dumped some MessageBox::Show's in my KeyDown event handler and sure enough, I am getting my messages back when the Function keys are pressed.</p> <p>The problem / dilemma however is that I can't seem to get the TabPage that corresponds to the Function Key Pressed to actually become the selected Tab Page. I have tried . . . "BringToFront", "Focus", "Enter" and "Click". None of these seem to do the trick to bringing the TabPage to the front.</p> <p>Here's my C++ Code . . .</p> <pre><code>System::Void frmBadgeScan_GeneralKeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) { switch (e-&gt;KeyCode) { case System::Windows::Forms::Keys::F3: e-&gt;Handled = true ; if (CurrentTab-&gt;Name-&gt;Equals("tabEmployeeScanOut")) btnClearOutList_Click (sender, nullptr) ; else if (CurrentTab-&gt;Name-&gt;Equals("tabEmployeeScanIn")) btnClearInList_Click (sender, nullptr) ; break ; case System::Windows::Forms::Keys::F5: e-&gt;Handled = true ; MessageBox::Show("F5") ; //this-&gt;tabEmployeeScanOut-&gt;BringToFront () ; //this-&gt;tabEmployeeScanOut-&gt;Focus () ; //tabEmployeeScanOut_Enter (sender, nullptr) ; break ; case System::Windows::Forms::Keys::F9: e-&gt;Handled = true ; MessageBox::Show("F9") ; //this-&gt;tabEmployeeScanIn-&gt;BringToFront () ; //this-&gt;tabEmployeeScanIn-&gt;Focus () ; //tabEmployeeScanIn_Enter (sender, nullptr) ; break ; } } System::Void tabEmployeeScanIn_Enter(System::Object^ sender, System::EventArgs^ e) { CurrentTab = this-&gt;tabEmployeeScanIn ; SendKeys::Send("{Tab}") ; } System::Void tabEmployeeScanOut_Enter(System::Object^ sender, System::EventArgs^ e) { CurrentTab = this-&gt;tabEmployeeScanOut ; SendKeys::Send("{Tab}") ; } </code></pre> <p>Any ideas?</p> <p>BTW, the variable "CurrentTab" is defined as . . .</p> <pre><code> TabPage ^ CurrentTab ; </code></pre> <p>Thanks in advance for the help!</p> <p>Oh, and all of the controls on the form are defined to capture the KeyDown event so regardless of what control has focus on the form, the KeyDown event will be fired . . .</p> <p>Like so . . .</p> <pre><code>this-&gt;stsBadgeScan-&gt;KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &amp;frmBadgeScan::frmBadgeScan_GeneralKeyDown); this-&gt;tabMainMenu-&gt;KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &amp;frmBadgeScan::frmBadgeScan_GeneralKeyDown); this-&gt;btnClearOutList-&gt;KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &amp;frmBadgeScan::frmBadgeScan_GeneralKeyDown); this-&gt;lstScanOut-&gt;KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &amp;frmBadgeScan::frmBadgeScan_GeneralKeyDown); this-&gt;txtEmplNumScanOut-&gt;KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &amp;frmBadgeScan::frmBadgeScan_GeneralKeyDown); this-&gt;KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &amp;frmBadgeScan::frmBadgeScan_GeneralKeyDown); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload