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
Solved

Accepting Returns

Posted on 2004-09-27
6
230 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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