Sunday, March 6, 2011

Stop arrow keys from scrolling through tabs on TabControl C# Winform

Basically the Title says it all, I need to keep the arrow keys from being able to scroll through my various tabs. Anyone know of a way to do this?

From stackoverflow
  • I think you can trap event "KeyPress" for that control

    then on the handle you have

    System::Windows::Forms::KeyPressEventArgs^  e
    

    You then check

    if (e->KeyChar == [find the number representing the arrow key])
      e->Handled = true; // Meaning that no one will receive it afterwards
    
  • I fixed the problem with the following code

    string tempstring = e.KeyValue.ToString();
    if (tempstring == "37" || tempstring == "38" || tempstring == "39" || tempstring == "40")
    {
         e.Handled = true;
    }
    

    I placed it inside of the tabControl1_KeyDown(object sender, KeyEventArgs e) method.

0 comments:

Post a Comment