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

#1 saumya9888  Icon 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

Hi,

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();
        if(!msg.trim().equalsIgnoreCase("")){
        jTextField1.setText("");
        jTextArea1.append(username+" Says:\n"+msg+"\n\n");
        JScrollBar sbver=jScrollPane1.getVerticalScrollBar();
        sbver.setValue(sbver.getMaximum());
        jTextField1.requestFocus();
        try {
            dos.writeUTF(msg);
            dos.flush();
        } catch (IOException ex) {
            Logger.getLogger(ChatHandler.class.getName()).log(Level.SEVERE, null, ex);
        }}
    }                                        

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        jButton1ActionPerformed(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  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • 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  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • 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