I'm writing an application that can solve Sudoku puzzles. I'm using a Bitmap to represent the grid visually. When I have a Cell selected, pressing a button should change its content. For some reason, the method I wrote won't trigger at all. Selecting stuff by clicking triggers just fine, but this method won't. Why?
KeyPress won't trigger
Started by anotheruser, Aug 04 2010 12:42 PM
11 replies to this topic
#1
Posted 04 August 2010 - 12:42 PM
|
|
|
#2
Posted 05 August 2010 - 09:33 AM
Hey mate,
I have a idea why, is it becuase your bitmap is covering the text?
If you could can you put your project in a zip folder and attach it, it will allow me and others to have a look and see from out perspective..
Cheers
Alex
I have a idea why, is it becuase your bitmap is covering the text?
If you could can you put your project in a zip folder and attach it, it will allow me and others to have a look and see from out perspective..
Cheers
Alex
#3
Posted 05 August 2010 - 10:07 AM
Alex3k said:
Hey mate,
I have a idea why, is it becuase your bitmap is covering the text?
I have a idea why, is it becuase your bitmap is covering the text?
THere is no text for the bitmap to cover. The bitmap is the entire thing (except for a "start solving" button in the corner).
#4
Posted 05 August 2010 - 10:23 AM
Here is some sourcecode, if that helps:
The function Form1_KeyPress was written by me. It doesn't even get called.
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);from Form1.InitializeComponent(). This was automatically generated and I don't understand why it won't work.
The function Form1_KeyPress was written by me. It doesn't even get called.
#5
Posted 06 August 2010 - 09:53 PM
Hmmmm, When i have always done keypress i have done it this way:
-----------------------------
At the code window there are two drop down boxes, in the first one click form1 events
in the second click keypress
and then your code inside that..
Hope that helps?
-----------------------------
At the code window there are two drop down boxes, in the first one click form1 events
in the second click keypress
and then your code inside that..
Hope that helps?
#6
Posted 14 August 2010 - 08:07 AM
That's what I did. I really can't explain to myself why this doesn't work. The other two events I use, Form1_MouseClick and Form1_Paint, work just fine, but this one won't. Is this a known bug or something?
PS: I HATE interfaces. Why do they make more problems than the code I write myself? Why can I get the program to solve a sudoku puzzle but can't convince the computer to accept my input?:cursing:
PS: I HATE interfaces. Why do they make more problems than the code I write myself? Why can I get the program to solve a sudoku puzzle but can't convince the computer to accept my input?:cursing:
#7
Posted 14 August 2010 - 09:52 AM
If you're adding a keypress handler to a form and want it to catch key presses even when a control on that form have focus you have to change KeyPreview of that form to True.
If you are trying to catch the keypresses of the arrow keys it won't work since they are also used to navigate through the controls of the form, to solve this set TabStop to False for all the controls of the form.
Hope this helps you.
If you are trying to catch the keypresses of the arrow keys it won't work since they are also used to navigate through the controls of the form, to solve this set TabStop to False for all the controls of the form.
Hope this helps you.
Edited by Vswe, 14 August 2010 - 01:40 PM.
#8
Posted 14 August 2010 - 11:27 AM
That first tip finally fixed it. Now I just wonder why this isn't mentioned anywhere. It seems like a problem that would occur more frequently, but I couldn't find anything with google.
Thanks a lot.
edit: I just decided to implement control through the arrow keys as well, but your suggestion how to enable them doesn't work. Is there anything else I need to do? I set the value to false for all controls in the Form. Do I have to change sth. on the Form itself?
Thanks a lot.
edit: I just decided to implement control through the arrow keys as well, but your suggestion how to enable them doesn't work. Is there anything else I need to do? I set the value to false for all controls in the Form. Do I have to change sth. on the Form itself?
Edited by anotheruser, 14 August 2010 - 01:15 PM.
#9
Posted 14 August 2010 - 01:38 PM
Yeah it's kinda strange it's not mentioned often, I remember I've had the problem more than once in the past. To your new problem, I'm sorry but I don't know anything more to do than setting all Tabstops to False. It should work. But can you see anything happen when you press on any of the arrow keys? Like a new control receiving focus or anything?
#10
Posted 15 August 2010 - 11:24 AM
yes, the controls switch focus. Something they shouldn't do, as I set TabStop to false for all of them.
#11
Posted 16 August 2010 - 05:11 AM
what kind of controls do you have?
#12
Posted 16 August 2010 - 10:25 AM
one TextBox that tells the user if an error occured and two Buttons to solve and reset the puzzle. Other than that, there is only the Bitmap that represents the Sudoku grid and its content.


Sign In
Create Account


Back to top









