tabControl and textBox Keypress event: textBox will not take input.

I'm working on a program that takes several inputs, does some calculations and then plots a graph.  The inputs are handled with a KeyPress event.  All of the textBoxes are in a groupBox control.  Everything was working fine until I decided to put the optional inputs on a separate tabControl with two tabPages.  In the process I did some cutting and pasting of the groupBox with the original textBoxes.  Cut some of the textBoxes out of the original groupBox and pasted them in a new groupBox on the new tabControl.  I also
created a new textBox and places it on the tabControl.

Now the original textBoxes will not accept any input and only beep when I press Return.  The only textBox that accepts input now is the new textBox on the tabControl that was created new (not cut and pasted).
I created a small program with a tabControl and  two textBoxes, one on the tabControl.  It worked fine, so I suspect that the cutting and pasting I did may have tangled something up.  I have tried debugging by stepping into the code, but it never gets to the Keypress event, I just get a beep.

Here's how the KeyPress events are handled:

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            char c = e.KeyChar;
            int i = (int)c;
            if (i == 13) // The "Return/Enter" key was pressed
            {
                e.Handled = true;
                if (textBox1.Text != "")
                {
                    inputOD = System.Convert.ToDouble(textBox1.Text);
                    Calculate();
                    this.ActiveControl = textBox2;
                }
                else
                    MessageBox.Show("Nothing was entered!", "Entry Error");
            }
        }
rturneyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Place a breakpoint in the first line of the textBox1_KeyPress event handler. If it does not break there when you run the application and attempt to add text to the TextBox then terminate the application and go to the design view and click on the textBox1 control and go to the property page and click on the events button and make sure that there is a event defined for the KeyPress event and that they are spelled the same way. The IDE might of removed the name when you cut and past code around.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rturneyAuthor Commented:
Sure enough, following your instructions, the app did not break at the first line of the Keypress event.  Selecting the textBox and double-clicking on the Keypress event created a new stub with:
private void textBox1_KeyPress_1(object sender, KeyPressEventArgs e).  It has added a "1" to the control name.  

Does this mean I now have to recreate the Keypress events for all the textboxes?
0
rturneyAuthor Commented:
Thanks to your info I have discovered, unlike VB6, when using Visual Studio languages, in this case C#, that moving a control like a textBox from a groupBox to somewhere else does not require you to cut it and then paste it.  It appears then you can drag the textBox out of the groupBox with no problem, where in VB6 you had to cut the control out of the groupBox.  So it seems that the cutting removed the textBox control from the event handler and when I pasted it back it had a new name?  Strange because the Properties doesn't show any newly named textBoxes.  They all have retained their old names.  The only evidence is when you double click the Keypress event handler that you see a "_1" was added.

What's the best way to clean up the mess?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Fernando SotoRetiredCommented:
If you go back to the property page for the control and select the KeyPress event by single clicking and then click on the down arrow in the ComboBox to the right you will find 2 or more event handlers that match the delegate of the TextBox. Select textBox1_KeyPress or textBox1_KeyPress_1 and delete the other in code. When you double clicked on the event you added another event method to the code seeming the default name was already in code it added the _1 to the end of the default name to create the new method.
0
rturneyAuthor Commented:
Thank you very much for your help.  I learned something new about the Visual Studio IDEs that is different from the VB6 IDE.
Best regards,
-Bob
0
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.  ;=)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.