vb中如何对图像框数组实现单个图像框的拖动与单击事件
vb中如何对图像框数组实现单个图像框的拖动与单击事件如何通过事件得到图像框的名字从而实现对其位置属性进行改变...
vb中如何对图像框数组实现单个图像框的拖动与单击事件
如何通过事件得到图像框的名字从而实现对其位置属性进行改变 展开
如何通过事件得到图像框的名字从而实现对其位置属性进行改变 展开
1个回答
展开全部
'窗体放置一个(仅一个)图像框 Image1,在属性窗口将 Index 属性设置为 0
'程序运行中可以像设计时一样,用鼠标拖动图像框
Dim ctX As Single, ctY As Single
Private Sub Form_Load()
Dim I As Long
Image1(0).Picture = Me.Icon '将窗体图标显示到图像框
For I = 0 To 4 '装数组载图像框 4 个
If I > 0 Then Load Image1(I): Image1(I).Visible = True
Image1(I).Move I * (Image1(0).Width * 1.2), Image1(0).Top
Next
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "移动鼠标,在窗体上 x=" & X & " y=" & Y
End Sub
Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
ctX = X: ctY = Y
Me.Caption = " 按下鼠标,在Image1(" & Index & ")上: x=" & X & " y=" & Y
End Sub
Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim X1 As Single, Y1 As Single
X1 = Image1(Index).Left + X - ctX: Y1 = Image1(Index).Top + Y - ctY
If Button = 1 Then Image1(Index).Move X1, Y1: Me.Caption = "拖动:Image1(" & Index & ").Left=" & X1 & " Top=" & Y1
If Button = 0 Then Me.Caption = "移动鼠标,在Image1(" & Index & ")上: x=" & X & " y=" & Y
End Sub
'程序运行中可以像设计时一样,用鼠标拖动图像框
Dim ctX As Single, ctY As Single
Private Sub Form_Load()
Dim I As Long
Image1(0).Picture = Me.Icon '将窗体图标显示到图像框
For I = 0 To 4 '装数组载图像框 4 个
If I > 0 Then Load Image1(I): Image1(I).Visible = True
Image1(I).Move I * (Image1(0).Width * 1.2), Image1(0).Top
Next
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "移动鼠标,在窗体上 x=" & X & " y=" & Y
End Sub
Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
ctX = X: ctY = Y
Me.Caption = " 按下鼠标,在Image1(" & Index & ")上: x=" & X & " y=" & Y
End Sub
Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim X1 As Single, Y1 As Single
X1 = Image1(Index).Left + X - ctX: Y1 = Image1(Index).Top + Y - ctY
If Button = 1 Then Image1(Index).Move X1, Y1: Me.Caption = "拖动:Image1(" & Index & ").Left=" & X1 & " Top=" & Y1
If Button = 0 Then Me.Caption = "移动鼠标,在Image1(" & Index & ")上: x=" & X & " y=" & Y
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询