473,378 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Keypress in a textbox.

I am using Visual Studio 2003 to develop a windows application in which I
allow the users to just press Enter, while the focus is on a textbox, in
order to perform a search. My problem is that sometimes Keypress event
stops being raised. I have found that I can reproduce this behavior by
performing a search, opening up another form, then trying to perform another
search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks
Nov 21 '05 #1
12 6515
I think we will need some simplified code that demonstrates the problem to
help you out.

Chris

"Todd Sparks" <co*******@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am using Visual Studio 2003 to develop a windows application in which I
allow the users to just press Enter, while the focus is on a textbox, in
order to perform a search. My problem is that sometimes Keypress event
stops being raised. I have found that I can reproduce this behavior by
performing a search, opening up another form, then trying to perform
another search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks

Nov 21 '05 #2
Here is the code that I am using.

Private Sub customerNumberSearch(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerNumber.KeyPress
If e.KeyChar = Chr(13) Then
'do search
End If
End Sub
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I think we will need some simplified code that demonstrates the problem to
help you out.

Chris

"Todd Sparks" <co*******@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am using Visual Studio 2003 to develop a windows application in which I
allow the users to just press Enter, while the focus is on a textbox, in
order to perform a search. My problem is that sometimes Keypress event
stops being raised. I have found that I can reproduce this behavior by
performing a search, opening up another form, then trying to perform
another search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks


Nov 21 '05 #3
That does not give me enough information to reproduce the error.

Chris

"Todd Sparks" <co*******@nospam.nospam> wrote in message
news:ev**************@TK2MSFTNGP14.phx.gbl...
Here is the code that I am using.

Private Sub customerNumberSearch(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerNumber.KeyPress
If e.KeyChar = Chr(13) Then
'do search
End If
End Sub
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I think we will need some simplified code that demonstrates the problem to
help you out.

Chris

"Todd Sparks" <co*******@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am using Visual Studio 2003 to develop a windows application in which I
allow the users to just press Enter, while the focus is on a textbox, in
order to perform a search. My problem is that sometimes Keypress event
stops being raised. I have found that I can reproduce this behavior by
performing a search, opening up another form, then trying to perform
another search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks



Nov 21 '05 #4
Does the second form you're bringing up have a button that is the form's
default? That might be stealing your keypress event so it's never raised.

Brian

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Building better tools for developers--be part of it!
Nov 21 '05 #5
When you say opening up another form, do you mean another instance of
the same form?

Aaron

Todd Sparks wrote:
Here is the code that I am using.

Private Sub customerNumberSearch(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerNumber.KeyPress
If e.KeyChar = Chr(13) Then
'do search
End If
End Sub
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I think we will need some simplified code that demonstrates the problem to
help you out.

Chris

"Todd Sparks" <co*******@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl.. .
I am using Visual Studio 2003 to develop a windows application in which I
allow the users to just press Enter, while the focus is on a textbox, in
order to perform a search. My problem is that sometimes Keypress event
stops being raised. I have found that I can reproduce this behavior by
performing a search, opening up another form, then trying to perform
another search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks



--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #6
I think Brian's hit the nail on the head.

Nov 21 '05 #7
Hi

I agree with Brian's suggestion.
Also I can not reproduce the problem with the code below.
Private Sub customerNumberSearch(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerNumber.KeyPress
If e.KeyChar = Chr(13) Then
dim fm as new form
fm.show
End If
End Sub

You may have a try and it is better to provide a reproduce sample.
Thanks.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #8
Todd,
When you test this, than it is maybe easier when you want to emulate
situoations which takes a time to try just routines as

Private Sub customerNumberSearch(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtCustomerNumber.KeyPress
If e.KeyChar = Chr(13) Then
threading.thread.sleep(7000)
End If
End Sub
That gives you in my opinion more the change to isolate your problem.

Just as idea

Cor

"Todd Sparks" <co*******@nospam.nospam>
...
I am using Visual Studio 2003 to develop a windows application in which I
allow the users to just press Enter, while the focus is on a textbox, in
order to perform a search. My problem is that sometimes Keypress event
stops being raised. I have found that I can reproduce this behavior by
performing a search, opening up another form, then trying to perform
another search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks

Nov 21 '05 #9
No, just opening up another form in my project.

At this point, I have been trying to use a process of elimination to
determine what is causing the problem. I have been removing steps from the
process and trying to determine which step causes the functionality to
break. Right now it seems to have something to do with the fact that when I
return to my 'main' form and change my search criteria and press the Enter
key it is trying to do the button-click that opened up the second form
instead of my search. Any ideas on how I can prevent this action?
"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:t1*******************@newssvr33.news.prodigy. com...
When you say opening up another form, do you mean another instance of the
same form?

Aaron

Todd Sparks wrote:
Here is the code that I am using.

Private Sub customerNumberSearch(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
txtCustomerNumber.KeyPress
If e.KeyChar = Chr(13) Then
'do search
End If
End Sub
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I think we will need some simplified code that demonstrates the problem
to help you out.

Chris

"Todd Sparks" <co*******@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl. ..

I am using Visual Studio 2003 to develop a windows application in which
I allow the users to just press Enter, while the focus is on a textbox,
in order to perform a search. My problem is that sometimes Keypress
event stops being raised. I have found that I can reproduce this
behavior by performing a search, opening up another form, then trying to
perform another search. The second search will NEVER work.

How can I fix this problem?

Thanks,
Todd Sparks


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Nov 21 '05 #10
No, none of my forms have default buttons. But I do think it has something
to do with this. Somehow I think my original form is remembering that the
last thing I did was press a button so whenever I am pressing the Enter key
it is trying to duplicate that action. So, I guess the real question then
is how can I prevent this from happening?

"Brian Schwartz" <br***@fishnetcomponentswos.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Does the second form you're bringing up have a button that is the form's
default? That might be stealing your keypress event so it's never raised.

Brian

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Building better tools for developers--be part of it!

Nov 21 '05 #11
Hi

You may take a look at the link below.

Trapping Enter key in Windows Forms TextBox
http://www.heikniemi.net/hc/archives/000122.html

We can inhertis a Textbox and then handle its KeyDown event
public class MyTextbox : System.Windows.Forms.TextBox
{
protected override bool IsInputKey(Keys key)
{
if (key == Keys.Enter)
return true;
return base.IsInputKey(key);
}
}

private void txtTest_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
this.lblValue.Text=this.txtTest.Text.Trim();
}
}
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #12
> Right now it seems to have something to do with the fact that when I
return to my 'main' form and change my search criteria and press the Enter
key it is trying to do the button-click that opened up the second form
instead of my search.


I'm not sure I'm following you, but if it's somehow "remembering" a keypress
later, what if you set the Handled property in the event to True?

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Building better tools for developers - Be part of it!
Nov 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new...
0
by: Steph. | last post by:
Hi, I have made a new custom TextBox control to enable ENTER and TAB keys to be trapped in the "KeyPress" and "KeyDown" Events. to do that I have overridden the "IsInputKey" property in my...
0
by: Hal Gibson | last post by:
Because of a legacy (originally DOS) Sub Procedure "AlphaInput" that is called in thousands of places in our code, I need to be able to set a variable, "KeyedString",to the value of TextBox.Text...
4
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
3
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I...
5
by: Henry Jones | last post by:
I am new to C# and wanted to capture the KeyPress for a textbox. I created some code as follows: private void textBox3_KeyPress(object sender, System.EventArgs e) { this.textBox2.Text =...
3
by: windy | last post by:
I got a question about keypress event on textbox: I found that the keypress event doesn't invoked when i press the "." button on alphabetic keyboard, however if i use numberpad's "." button...
2
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I...
2
by: Jason Huang | last post by:
Hi, How do I override a TextBox's KeyPress evnt? And how do we use it? Thanks for help. Jason
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.