Solved

Accepting Returns

Posted on 2004-09-27
6
228 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now