keypress event help!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xoxkrissyxox
    New Member
    • Jan 2009
    • 1

    keypress event help!!

    I'm making a calculator in C# and i have a keypress event set up. It works and all I just want to know if theres a way to not display what key i press in the textbox. Thanks :)
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Cancel the event in the event handler using the args

    Comment

    • satyam90
      New Member
      • Jan 2009
      • 7

      #3
      Originally posted by xoxkrissyxox
      I'm making a calculator in C# and i have a keypress event set up. It works and all I just want to know if theres a way to not display what key i press in the textbox. Thanks :)
      Implement your own event to handler to handle key press event. then call parent key event handler and return false so that it won't display ur keystroke.

      Comment

      • satyam90
        New Member
        • Jan 2009
        • 7

        #4
        sorry for the last reply. it won't work in C#. i was thinking about some other programming language and mentioned it in previously reply.
        Actual thing will something like below:

        For example you want to suppress the key "i"
        private void Form1_KeyDown(o bject sender, KeyEventArgs e)
        {
        if (e.KeyCode != Keys.i)
        {
        textbox1.Text = e.KeyCode;
        // Don't pass message to other controls
        e.Handled = true;
        }
        }
        }

        Comment

        • dschu012
          New Member
          • Jul 2008
          • 39

          #5
          If you make the set the textbox ReadOnly Property to true, it will allow you to set the text programmaticall y while not allow users to enter text.

          Comment

          Working...