2 Replies - 1535 Views - Last Post: 09 July 2011 - 05:03 PM Rate Topic: -----

#1 saumya9888   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 08-August 08

How to detect enter pressed in a text field

Posted 09 July 2011 - 01:33 PM


I am new to coding in C#, we were given a simple exercise to write into text field and on press of a button, messagebox pops up with same text.

I have done some coding in java and I made a chat application with a chat window , where I have defined the task of appending into textarea into pressbutton event and called that function from textfield action performed event like this

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String msg=jTextField1.getText();
        jTextArea1.append(username+" Says:\n"+msg+"\n\n");
        JScrollBar sbver=jScrollPane1.getVerticalScrollBar();
        try {
        } catch (IOException ex) {
            Logger.getLogger(ChatHandler.class.getName()).log(Level.SEVERE, null, ex);

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            

My question is whether there is any simple way to achieve this in C#, simple way as in without the manipulation of 'textfield.Text' returned string.

Is This A Good Question/Topic? 0
  • +

Replies To: How to detect enter pressed in a text field

#2 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12306
  • View blog
  • Posts: 45,403
  • Joined: 27-December 08

Re: How to detect enter pressed in a text field

Posted 09 July 2011 - 03:52 PM

Moved to C#. Please don't open help threads in the tutorials sections.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: How to detect enter pressed in a text field

Posted 09 July 2011 - 05:03 PM

You can use a number of the Key events for a Textbox. For this specific excercise, I would probably use the KeyUp event.

In this event, you can use the KeyEventArgs class to get the key that was pressed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1