I would like to share some improvements I have made. (changes in bold)
Code:Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If X < 0 Or Y < 0 Or X > EventsCommandButton.Width Or Y > EventsCommandButton.Height Then If Button = vbLeftButton Then Picture1.Enabled = True ' if using Picture1 as a dummy control, we'll make sure it is enabled, otherwise the SetFocus method will trigger an error Picture1.SetFocus Command1.SetFocus Picture1.Enabled = False ' disable the Picture1 Picture1.Move picleft, pictop Picture1.Refresh End If End If End SubCode:Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Picture1.Move picleft, pictop Picture1.Refresh End If End SubThis I have added to react when hitting the space key on the command button (like mouse clicking):Code:Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then Picture1.Move picleft, pictop Picture1.Refresh End If End Sub
Code:Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeySpace Then Picture1.Move picleft + 15, pictop + 15 End Sub Private Sub Command1_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeySpace Then Picture1.Refresh End Sub Private Sub Command1_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeySpace Then Picture1.Move picleft, pictop End Sub




Reply With Quote