请问在vb的一个窗体里,有一个button1,如何实现按下上下左右中的一个键,这个按钮能上下左右移动。
1个回答
展开全部
form1.keypreview 属性设为 true
----------------------------------------
Public Class Form1
Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Dim x As Integer, y As Integer
x = Button1.Left
y = Button1.Top
Select Case e.KeyCode
Case Keys.Up
y = y - 10
Case Keys.Down
y = y + 10
Case Keys.Left
x = x - 10
Case Keys.Right
x = x + 10
End Select
Button1.Left = x
Button1.Top = y
End Sub
End Class
----------------------------------------
Public Class Form1
Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Dim x As Integer, y As Integer
x = Button1.Left
y = Button1.Top
Select Case e.KeyCode
Case Keys.Up
y = y - 10
Case Keys.Down
y = y + 10
Case Keys.Left
x = x - 10
Case Keys.Right
x = x + 10
End Select
Button1.Left = x
Button1.Top = y
End Sub
End Class
追问
啊。。。不用了不用了,谢谢,我一时没看懂
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询