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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form {
private TextBox2 textBox1;
[STAThread]
static void Main() {Application.Run(new Form1());}
public Form1() {InitializeComponent();}
#region Windows Form Designer generated code
private void InitializeComponent() {
this.textBox1 = new TextBox2();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(224, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.textBox1.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.textBox1 _KeyDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e) {
MessageBox.Show(e.KeyCode.ToString());
}
}
public class TextBox2:TextBox {
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*******@discussions.microsoft.com> a écrit dans le message de
news:C2**********************************@microsof t.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.ModifierKeys == Keys.Tab),
checked for it by
MessageBox.Show((e.KeyValue).ToString()); (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