vb6.0中,放一个image控件,单击这个控件,可以在原地复制一个,并且可以拖动它到任意位置,怎样实现?
复制这个控件是用控件数组吗?俺是新手,求教了!我的意思是拖动新的image控件后,原来的控件不动,就好像在原地复制出一个的感觉。可以拖出任意个数,并且新的控件要可以随意移...
复制这个控件是用控件数组吗?俺是新手,求教了!
我的意思是拖动新的image控件后,原来的控件不动,就好像在原地复制出一个的感觉。可以拖出任意个数,并且新的控件要可以随意移动位置。 展开
我的意思是拖动新的image控件后,原来的控件不动,就好像在原地复制出一个的感觉。可以拖出任意个数,并且新的控件要可以随意移动位置。 展开
展开全部
rem 以下程序可以实现你的要求
rem 窗体中要建立2个图像框,第1个不可移动,第2个可移动
Dim x1 As Integer 'x坐标
Dim y1 As Integer 'y坐标
Private Sub Form_Load()
Image1.Visible = True
Image2.Visible = False
Image1.Stretch = True
Image2.Stretch = True
Image1.Picture = LoadPicture(App.Path & "\00.jpg")
Image2.Picture = LoadPicture(App.Path & "\00.jpg")
End Sub
Private Sub Image1_Click()
Image2.Top = Image1.Top
Image2.Left = Image1.Left
Image2.Width = Image1.Width
Image2.Height = Image1.Height
Image2.Visible = True
End Sub
Private Sub Image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = X
y1 = Y
Image2.MousePointer = 5
End Sub
Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If x1 <> 0 And y1 <> 0 Then
Image2.Left = Image2.Left + (X - x1)
Image2.Top = Image2.Top + (Y - y1)
End If
End Sub
Private Sub Image2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = 0
y1 = 0
Image2.MousePointer = 0
End Sub
rem 窗体中要建立2个图像框,第1个不可移动,第2个可移动
Dim x1 As Integer 'x坐标
Dim y1 As Integer 'y坐标
Private Sub Form_Load()
Image1.Visible = True
Image2.Visible = False
Image1.Stretch = True
Image2.Stretch = True
Image1.Picture = LoadPicture(App.Path & "\00.jpg")
Image2.Picture = LoadPicture(App.Path & "\00.jpg")
End Sub
Private Sub Image1_Click()
Image2.Top = Image1.Top
Image2.Left = Image1.Left
Image2.Width = Image1.Width
Image2.Height = Image1.Height
Image2.Visible = True
End Sub
Private Sub Image2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = X
y1 = Y
Image2.MousePointer = 5
End Sub
Private Sub Image2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If x1 <> 0 And y1 <> 0 Then
Image2.Left = Image2.Left + (X - x1)
Image2.Top = Image2.Top + (Y - y1)
End If
End Sub
Private Sub Image2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = 0
y1 = 0
Image2.MousePointer = 0
End Sub
追问
谢谢!但是和我希望的不太一样。就是鼠标在image1上按下后,就应该复制出一个控件,这时两个控件的位置是重合的,拖动鼠标时,第二个控件随意移动并可以放在任何位置,第一个控件还在那里。你的程序运行后,无法拖拽出第二、三。。。个控件。
追答
你原来只说要复制一个,现在又要无数个,这个是有很大区别的,按此思路自己去实现吧
展开全部
Dim MoveX As Integer, MoveY As Integer '定义鼠标的位置
Dim n As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveX = X - Image1(n).Width / 2 '把SHAPE1的几何中心坐标值赋给鼠标坐标
MoveY = Y - Image1(n).Height / 2 '
Image1(n).Move MoveX, MoveY '把SHAPE1移到鼠标的位置
End Sub
Private Sub Image1_Click(Index As Integer)
n = n + 1
Load Image1(n)
Image1(n).Visible = True
End Sub
Dim n As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveX = X - Image1(n).Width / 2 '把SHAPE1的几何中心坐标值赋给鼠标坐标
MoveY = Y - Image1(n).Height / 2 '
Image1(n).Move MoveX, MoveY '把SHAPE1移到鼠标的位置
End Sub
Private Sub Image1_Click(Index As Integer)
n = n + 1
Load Image1(n)
Image1(n).Visible = True
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询