vb中 当鼠标点击shape不同部位,shape如何驶向不同方向?
2个回答
展开全部
shape不接受事件,你可以用image代替,效果差不多,代码如下:
Private Sub Form_Load()
Image1.BorderStyle = 1
Image1.Appearance = 0
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X - Image1.Width / 2 > 0 Then
Image1.Left = Image1.Left + 300
Else
Image1.Left = Image1.Left - 300
End If
If Y - Image1.Height / 2 > 0 Then
Image1.Top = Image1.Top + 300
Else
Image1.Top = Image1.Top - 300
End If
End Sub
点击左上角就往左上移动,点击右下就往右下移动
Private Sub Form_Load()
Image1.BorderStyle = 1
Image1.Appearance = 0
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X - Image1.Width / 2 > 0 Then
Image1.Left = Image1.Left + 300
Else
Image1.Left = Image1.Left - 300
End If
If Y - Image1.Height / 2 > 0 Then
Image1.Top = Image1.Top + 300
Else
Image1.Top = Image1.Top - 300
End If
End Sub
点击左上角就往左上移动,点击右下就往右下移动
更多追问追答
追问
很好很好
但是在图片框里程序怎么就运行不了了?
追答
你是说把Image1放在图片框内还是用picture1代替image1?如果是前者是可以运行的,但是注意form-load里的代码不要忘记了,否则看不出来image1的存在;如果是后者就要改相应的代码了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询