| | |
Keypress not working
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 4
Reputation:
Solved Threads: 0
Hello I am working on a simple calculator program for school. I already have all the button clicks working, which is all that was required.
I thought it would be cool if I could get it to where you could use the keyboard for entry and I've done similar things with Visual Basic (which I learned in high school).
I looked online and found the syntax (I'm pretty sure its right) but for some reason it's not sensing a keypress event.
This is the code I have right now, I just want to get the keypress working, I already know how to do the specifics inside the event once it is working.
Oh and I do have keypreview enabled on my form.
Thanks in advance for the help and like I said, Its already done as far as the assignment was, I just want to learn how to do this.
I thought it would be cool if I could get it to where you could use the keyboard for entry and I've done similar things with Visual Basic (which I learned in high school).
I looked online and found the syntax (I'm pretty sure its right) but for some reason it's not sensing a keypress event.
This is the code I have right now, I just want to get the keypress working, I already know how to do the specifics inside the event once it is working.
Oh and I do have keypreview enabled on my form.
C# Syntax (Toggle Plain Text)
private void calculator_KeyPress(object sender, System.Windows.Forms.KeyEventArgs e) { textBox1.Text = "key pressed"; }
Thanks in advance for the help and like I said, Its already done as far as the assignment was, I just want to learn how to do this.
From Form properties make Key preview property true, in case your answer to Lizr question is YES.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Jan 2009
Posts: 4
Reputation:
Solved Threads: 0
Keypreview is enabled, I think I said that in my original post, but maybe not. Anyway I am using visual c# express to create this and I got the code for the keypress by using MSDN Here: http://msdn.microsoft.com/en-us/libr...ss.aspx?ppud=4
I couldn't find a way to automatically add in a keypress in visual express. I manually added in the method based upon the msdn example. I am still new to this program, so maybe I just haven't found it yet.
If this isn't what you meant, please let me know and if you know a way to add in the keypress method without manually typing it please let me know.
I couldn't find a way to automatically add in a keypress in visual express. I manually added in the method based upon the msdn example. I am still new to this program, so maybe I just haven't found it yet.
If this isn't what you meant, please let me know and if you know a way to add in the keypress method without manually typing it please let me know.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
I guess changing from the properties to events in the bottom right (by default) was missing..
So.. Im gonna take an educated guess you didnt tie the event to the method you made??
So.. Im gonna take an educated guess you didnt tie the event to the method you made??
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
•
•
Join Date: Jan 2009
Posts: 4
Reputation:
Solved Threads: 0
I'm not entirely sure what you mean, considering I am still new to making forms in c# (I was introduced to the language last semester where all we did was command line programs) but I think I know what you mean.
If I understand you correctly there is something I have to do to get the method to be called whenever a key is pressed. If so then you are correct I don't have this.
Also the only thing in the bottom (right or left) is the error list when in code view and the properties window in design view.
Btw thanks for the quick reply.
If I understand you correctly there is something I have to do to get the method to be called whenever a key is pressed. If so then you are correct I don't have this.
Also the only thing in the bottom (right or left) is the error list when in code view and the properties window in design view.
Btw thanks for the quick reply.
When yo are in design view and you press the little button with the lightning symbol on it, in the properties window. You get a list of all available events for the control currently selected. Double click the event you want and you will get into the code view in the eventhandler you just doubleclicked. Type in the code you want to do, it will work. The grungy details of the event handling are taken care of in the in the forms.designer.cs class.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- Alt+some key in KeyPress event (Visual Basic 4 / 5 / 6)
- Disabling Print Screen keypress in IE (JavaScript / DHTML / AJAX)
- Detecting any key being pressed. (VB.NET)
- KeyPress event with holding down the key (Python)
- KeyPress event not working (C#)
- Loan Program needs work (C++)
- Another dead Armada M700 (Troubleshooting Dead Machines)
- buttons and events? (Python)
Other Threads in the C# Forum
- Previous Thread: DataGridView property not working as expected
- Next Thread: Message Box
Views: 1649 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






