Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating a custom Textbox control
Message
 
To
01/01/2016 15:17:43
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01629510
Message ID:
01629511
Views:
57
Can you check whether the event is actually fired? KeyPress and KeyDown handle keys differently and some keys don't trigger one or the other.

Also you probably don't want to call the base method even with e.Handled set since you're essentially taking over that key event. The base call might affect your SendKeys logic.

+++ Rick ---


>I have often have a need for a textbox to tab to the next control when the user hits Enter, as it does with VFP.
>
>I've been using this syntax and it works
>
>  TextBoxHundreds.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SendTabonEnter);
>    
> private void SendTabonEnter(object sender, KeyEventArgs e)
>    {
>      if (e.KeyCode == Keys.Return)
>      {
>        SendKeys.Send("{TAB}");
>      }
>    }
>
>
>I've been trying to create a custom textbox control that has the behavior built in, with no success.
>I found this syntax, but it doesn't work.
>
>
>public class WSGTextbox : TextBox
>    {
>
>        protected override void  OnKeyDown(KeyEventArgs e)
>        {
>                if (e.KeyCode == Keys.Return)
>                {
>                    SendKeys.Send("{TAB}");
>                }
>                e.Handled = true;
>            //  to Call the implementation in the base TextBox class,
>            // which raises the KeyPress event.
>            base.OnKeyDown(e);
>        }
>
>
>
>    }
>
>
>Any ideas?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform