I think you did not properly used the code for IsInputKey. It must be the
overriden method of the control you want Tab key be caught.
Try the following lines (copy/paste it in a new project) :
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
public class Form1 : System.Windows. Forms.Form {
private TextBox2 textBox1;
[STAThread]
static void Main() {Application.Ru n(new Form1());}
public Form1() {InitializeComp onent();}
#region Windows Form Designer generated code
private void InitializeCompo nent() {
this.textBox1 = new TextBox2();
this.SuspendLay out();
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(16, 16);
this.textBox1.N ame = "textBox1";
this.textBox1.S ize = new System.Drawing. Size(224, 20);
this.textBox1.T abIndex = 0;
this.textBox1.T ext = "textBox1";
this.textBox1.K eyDown += new
System.Windows. Forms.KeyEventH andler(this.tex tBox1_KeyDown);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.textBox 1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);
}
#endregion
private void textBox1_KeyDow n(object sender,
System.Windows. Forms.KeyEventA rgs e) {
MessageBox.Show (e.KeyCode.ToSt ring());
}
}
public class TextBox2:TextBo x {
protected override bool IsInputKey(Keys keyData) {
if (keyData==Keys. Tab) return true;
return base.IsInputKey (keyData);
}
}
It should work fine.
Hope it helps,
Ludovic SOEUR.
"melanieab" <me*******@disc ussions.microso ft.com> a écrit dans le message de
news:C2******** *************** ***********@mic rosoft.com...
Hi,
Just checking to see if there's anything I can possibly do to allow for
the recognition of the Tab key being pressed. On the KeyDown event I've
tried:
if (e.KeyCode == Keys.Tab),
if (Control.Modifi erKeys == Keys.Tab),
checked for it by
MessageBox.Show ((e.KeyValue).T oString()); (it responded to every key I
tried except for Tab)),
even entered
protected override bool IsInputKey(Keys keyData)
{
if (keyData==Keys. Tab) return true;
return base.IsInputKey (keyData);
}
from a reply someone else got on the same subject (it worked for them, so
maybe I did something wrong? - I put it at the beginning of my program and
then tried the keycode thing again).
The Tab key tabs just fine, it just won't do anything else.
Thanks so much for any help!!!!
Yours frustrated,
Mel