views:

184

answers:

0

I'd like to handle the Enter button in my TextBox inside ListBox in UserControl (not Form!). There are a lot of answers and samples for the case. The most common is to override ProcessCmdKey() or IsInputKey() in CustomTextBox inherited from TextBox:

public class CustomizedTextBox : System.Windows.Forms.TextBox
{
    protected override bool ProcessCmdKey(ref Message m, Keys k)
    {
        /// Handling
    }

    protected override bool IsInputKey(Keys keyData)
    {
        if (keyData == Keys.Enter)
            return false;

        return base.IsInputKey(keyData);
    }

}

Then use it:

System.Windows.Forms.ListBox listBoxWithTextBox;        /// ListBox to be edited
CustomizedTextBox myTextBox = new CustomizedTextBox();  /// TextBox editing
myTextBox.Parent = listBoxWithTextBox;
this.listBoxWithTextBox.Controls.Add(this.myTextBox);

Everything's fine with the only problem. Neither ProcessCmdKey nor IsInputKey don't get called. Never.

What may be the problem?