peter

peter

  • NA
  • 6
  • 0

Defining behavior for Up keyPress

Apr 17 2010 9:17 AM


I have a Windows forms based Telnet client where I want to define the behaviour of certain keystrokes in the RichTextBox holding user data to send.
You can see from the code below that the 'enter/return' key will send the RichTextBox contents + a newline character '\n' and the 'escape' key will clear the RichTextBox. Both work fine. I cannot find any which way to define the behaviour of the 'Up' key. The RichTextBox is not multiline and is not word wrap so it is not as though there needs to be a default behaviour for the 'Up' key. At the moment, for testing purpose, I am trying to define the 'Up' key to simply display a message box.

private void rtbInput_KeyPress(object sender, KeyPressEventArgs e)
{
   switch (e.KeyChar)
   {
      case (char)Keys.Return :
         if (TELNET_CLIENT != null && TELNET_CLIENT.Connected)
         {
            string TEXT_TO_SEND = rtbInput.Text.Trim();
            if (!string.IsNullOrEmpty(TEXT_TO_SEND))
            {
               UpdateHistory(TEXT_TO_SEND);
               bgwMain.RunWorkerAsync(TEXT_TO_SEND +
Environment.NewLine);
               byte[] BYTES_TO_SEND = Encoding.ASCII.GetBytes(TEXT_TO_SEND + "\n");
               TELNET_CLIENT.BeginSend(BYTES_TO_SEND, 0, BYTES_TO_SEND.Length,
SocketFlags.None, new AsyncCallback(SocketSend), TELNET_CLIENT);
            }
         }
         rtbInput.Clear();
         break;
      case (char)Keys.Escape :
         rtbInput.Clear();
         break;
      case (char)Keys.Up :
         MessageBox.Show("hello");
         break;
   }
}
 

Answers (2)