Link to home
Start Free TrialLog in
Avatar of fattumsdad
fattumsdad

asked on

Accepting Returns

I have a multiline text box followed by a command button.  When the command button is pressed, it takes the text in the multiline box and sends it over a LAN (net send).  Is there a way to accomplish this same task, by pressing ENTER in the text box after the message is typed?
Avatar of Timbo87
Timbo87

Is this a Windows app or web app?
SOLUTION
Avatar of w_shaila
w_shaila

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fattumsdad

ASKER

Do I have to set any specific properties on txtMessage (the multiline text box)?  None of the above code is working...  when I press enter, it just puts me to the next line on the text box.  I tried AcceptsReturn true and false...  neither work :(
You need to register your function with the text box's keyup or keypress event.  For example:

to catch keypress:
TextBox tb...
// this is an event set to call your delegate
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
...

//This was coppied from w_shaila's post
private void tb_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
          {
               if (e.KeyChar == (char)13)
               {
                    MessageBox.Show("Test");
               }
          }