
Originally Posted by
jmcilhinney
Neither your code nor your explanation actually makes sense. Presumably you want to know whether the Location of the Button falls within the box described by those two Points as opposite corners. Is that correct? If so then you have two choices:
1. Examine the X and Y components of the Location separately and determine whether they are each within the appropriate range:
Code:
If e.KeyCode = Keys.Space AndAlso
BtnSprite.Left >= 12 AndAlso
BtnSprite.Left <= 80 AndAlso
BtnSprite.Top >= 330 AndAlso
BtnSprite.Top <= 380 Then
MessageBox.Show("Txt here")
End If
2. Construct the box and see if it contains the Location:
Code:
Dim box As New Rectangle(12, 330, 80 - 12, 380 - 330)
If e.KeyCode = Keys.Space AndAlso box.Contains(BtnSprite.Location) Then
MessageBox.Show("Txt here")
End If
Thanks so much, you professional. The second one was exactly it! Now I want to make the button move faster while holding shift across the form.
My Code:
Code:
If Keys.LShiftKey And e.KeyCode = Keys.W Then
BtnSprite.Location += New Point(0, -5) 'Added Location value to W using shift
End If
Original without shift:
Code:
If e.KeyCode = Keys.W Then
BtnSprite.Location += New Point(0, -1) 'Added Location value to W
End If