Solved

Accepting Returns

Posted on 2004-09-27
6
232 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:fattumsdad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Expert Comment

by:Timbo87
ID: 12164603
Is this a Windows app or web app?
0
 
LVL 3

Assisted Solution

by:w_shaila
w_shaila earned 100 total points
ID: 12164612
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
            {
                  if (e.KeyChar == (char)13)
                  {
                        MessageBox.Show("Test");
                  }
            }


For Example Sake I am using MessageBox . you can write the same code where you have written in button control
or write a generic function which you can call in button Click and in the above code
0
 
LVL 3

Accepted Solution

by:
GrumbleBot earned 300 total points
ID: 12164973
You could also select the command button on the forms AcceptButton property. If this is a winform that is. not sure if it works on web from or not. This will make that the default button on the form and when enter is pressed it is the same as clicking on the command button.

Good luck
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Assisted Solution

by:dsabo
dsabo earned 100 total points
ID: 12165179
You could handle the keyup or keydown event. I recomend the keyup event...

private void txtUsr_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
        if(e.KeyData == System.Windows.Forms.Keys.Enter)
        {
      //your code here
         }
}

I hope this helps, David S
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12165627
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 :(
0
 
LVL 4

Expert Comment

by:thedude112286
ID: 12165721
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");
               }
          }
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question