|
-
Sep 8th, 2011, 12:53 AM
#1
Thread Starter
New Member
Issue with keydown Space/Enter
Hi guys,
I am using vb.net within visual studio 2008.
I am using a picture box. I want to be able to use the Space or Enter key to change the image in it. For that, I try to use the keydown function as follow:
Code:
Private Sub ChestWindow_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.NumPad1
NextChest()
Case Keys.Enter
NextChest()
Case Keys.Space
NextChest()
End Select
End Sub
NextChest() is the function which changes the image. It works well when I press '1' on my numeric part of the keyboard as a test.
The issue is that when I press Space or Enter, the form containing the picturebox closes. (I've already put the keyPreview property to True)
I really do not understand. Do these keys have any default behavior? How can I do to make them doing what I want?
Thanks for your help!
Did
-
Sep 8th, 2011, 01:05 AM
#2
Hyperactive Member
Re: Issue with keydown Space/Enter
The keycode seems to be fine. The problem might be with the NextChest function.
-
Sep 8th, 2011, 01:09 AM
#3
Thread Starter
New Member
Re: Issue with keydown Space/Enter
Hi Ram2Curious,
Thanks for your very fast answer.
I am nearly sure that the issue is here. I've been using this function for a while, and I never had any problem with it.
another strange thing is that when the function is written as follow, the same thing happens with space and enter keys ...
Code:
Private Sub ChestWindow_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.NumPad1
NextChest()
End Select
End Sub
Thanks
Did
-
Sep 8th, 2011, 01:31 AM
#4
Addicted Member
Re: Issue with keydown Space/Enter
didAus please check your Form Property : "AcceptButton"
-
Sep 8th, 2011, 01:37 AM
#5
Thread Starter
New Member
Re: Issue with keydown Space/Enter
Hi medsont, my property "AcceptButton" is set "(none)". What should it be ?
thanks
-
Sep 8th, 2011, 01:40 AM
#6
Addicted Member
Re: Issue with keydown Space/Enter
Accept button
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx
please post your Nextchest function here.....
-
Sep 8th, 2011, 02:41 AM
#7
Thread Starter
New Member
Re: Issue with keydown Space/Enter
Here is my NextChest() function:
Code:
Private Sub NextChest()
countParity += 1
PB_imgChest.Tag = "not draw"
Refresh()
If FirstWindow.CB_ViewNumber.Text = "1 View, No Feedback" Then
If (countImg = tabImg.Length - 1) Then 'End of the 50 images
FirstWindow.StopTracking() 'Stop the tracking
FirstWindow.ETdataToTxt() 'send data from datagridview to txt file
Me.Close() ' Close the window
End If
If (countImg < tabImg.Length - 1) Then 'less than 50 images
countImg = countImg + 1 'increase the counter
DisplayChest(countImg)
LB_view.Text = 1 '1st view of this image
End If
The counter countImg is set to 0 at the loading of the form. I am sure that it's not equal to tabImg.Length-1 when I have the issue.
Thanks guys
Did
-
Sep 8th, 2011, 03:08 AM
#8
Addicted Member
Re: Issue with keydown Space/Enter
Hai DidAus... please try this below code if it will work i'm very happy otherwise VBFORUMS has more superior programmers so someone is might help you...........
vb Code:
Private Sub ChestWindow_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown Select Case e.KeyCode Case Keys.NumPad1 NextChest(e) End Select End Sub Private Sub NextChest(ByVal e As System.Windows.Forms.KeyEventArgs) countParity += 1 PB_imgChest.Tag = "not draw" Refresh() If FirstWindow.CB_ViewNumber.Text = "1 View, No Feedback" Then If (countImg = tabImg.Length - 1) Then 'End of the 50 images FirstWindow.StopTracking() 'Stop the tracking FirstWindow.ETdataToTxt() 'send data from datagridview to txt file 'because u r closing the form here...... If e.KeyData = Keys.Enter OrElse e.KeyData = Keys.Space Then Return Else Me.Close() ' Close the window End If End If If (countImg < tabImg.Length - 1) Then 'less than 50 images countImg = countImg + 1 'increase the counter DisplayChest(countImg) LB_view.Text = 1 '1st view of this image End If End Sub
-
Sep 8th, 2011, 03:22 AM
#9
Thread Starter
New Member
Re: Issue with keydown Space/Enter
Thanks for your suggestion. I will try that and let you know how it works !
Can you explain me what you did exactly ? I'm not sure I understand ...
Did
-
Sep 8th, 2011, 03:29 AM
#10
Addicted Member
Re: Issue with keydown Space/Enter
hey please, first post it's working or not.......... i just stopped to close the form ["Me.Close()]
if current keycode is Enter or Space thats all.....
-
Sep 8th, 2011, 07:17 PM
#11
Thread Starter
New Member
Re: Issue with keydown Space/Enter
Hi medsont, I just tried it, and unfortunately it doesn't works. The same thing is still happening...
But thanks for your help, I really appreciate!
-
Sep 9th, 2011, 12:12 AM
#12
Addicted Member
Re: Issue with keydown Space/Enter
it's k .....if you can not find the exact error write your code with in Try...Catch block..........
vb Code:
Try 'your codes here Catch ex As Exception MessageBox.Show(ex.ToString, "Error: " & Err.Number, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try
-
Sep 9th, 2011, 12:33 AM
#13
Thread Starter
New Member
Re: Issue with keydown Space/Enter
I am so sorry...it still does the same thing ...
-
Sep 9th, 2011, 02:17 AM
#14
Hyperactive Member
Re: Issue with keydown Space/Enter
Is the AcceptButton property set on the Picturebox Forms? If so try removing the value. Other than that I agree with medsont, the KeyDown event looks fine (although it is fired by the Forms Keydown event. Is that right? Or is meant to fire on the Keydown event of the Picturebox?)
If none of the above things are the problem perhaps you could post the project files for a deeper look into the problem. As it may be that there are other events in your project that are causing the behaviour.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|