Windows Develop Bookmark and Share   
 index > Windows Forms General > Keypresses in picture box
 

Keypresses in picture box

i have a small app where users can draw shapes in a picture box using the mouse. I want the 'delete' key, when pressed to delete the current shape. But there is no way (that i can see) to be able to listen to key events for a picture box.

Any ideas around this?
Speedie  Tuesday, February 20, 2007 9:08 AM

Hi speedie,

There is a property called “KeyPreview�for a Form which determines whether keyboard events for controls on the Form are registered with the Form. Please set it to “True�and try again so that the events work correctly.

“KeyUp�or “KeyDown�events will determine if “Delete�button is pressed (KeyPress event didn’t get fired in my app).

Thanks,

JDee

Jayadev D  Wednesday, February 21, 2007 5:28 AM

Hi,

I could see thatthere is no keyboard related events for a picture box. If I am not wrong I think you could handle the keypress event of the Form (container of the picture box) and somehow associate to your picture box.

Thanks,

JDee

Jayadev D  Tuesday, February 20, 2007 1:43 PM
I thought the same, i had a little play around today (had some other pressing problems so not so much time), but the form has a panel which is dock:fill. It appears the form never responds to a key press.

I put an event listener on the form for keypress, with a breakpoint and i never kicked in.
I then thought "aha, put it on the panel" but panel wont accept keypresses the same as the picturebox.
Speedie  Tuesday, February 20, 2007 4:46 PM

Hi speedie,

There is a property called “KeyPreview�for a Form which determines whether keyboard events for controls on the Form are registered with the Form. Please set it to “True�and try again so that the events work correctly.

“KeyUp�or “KeyDown�events will determine if “Delete�button is pressed (KeyPress event didn’t get fired in my app).

Thanks,

JDee

Jayadev D  Wednesday, February 21, 2007 5:28 AM
Thanks alot, that 'keyPreview' has done the trick.

Sending good karma to the universal time space you occupy today
Speedie  Wednesday, February 21, 2007 9:33 AM
Hi,
I am also facing a similar kind of problem and tried“KeyPreview" property but it did not work out.
I have a picture box called PictureBox1 which along with a Horizontal and a Vertical scroll bar is placed onto another Picture Box called MyPictureBox.MyPicturebox is thus a user Control and this User Control opens inside a Form called frmMain whose“KeyPreview" property is set to true.
I want to capture the keypress events of picturebox 1 n e ideas??
:(
Ashish Agrawal
NewBie_in_CSharp  Tuesday, February 03, 2009 1:46 PM
Hi,
My problem is solved.Did a silly mistake,focus was not set on the inner picture box and so it was not working.
Ashish Agrawal
NewBie_in_CSharp  Thursday, February 05, 2009 1:33 PM

You can use google to search for other answers

Custom Search

More Threads

• Reduce SPACE
• How to make a pop-up 'balloon' Notification
• Add Autogenerated Serial Number in Datagrid
• Screensaver Events and performing functions just prior to ss execution.
• Autocomplete combo box woes.
• do something till x minutes after running the program
• masked text boxes.
• Icon Colors
• Adding a code to an existing form
• Dataset with multiple relationships and combo boxes