当我移动并将其放置在运行时的另一个图片框上时,如何避免图片框消失?

问题描述 投票:0回答:1

我测试了这个网页中用于在运行时移动图片框的代码:http://www.davidsuarez.es/2007/11/mover-y-soltar-controles-con-drag-drop-visual-basic/

我创建了一个带有两个pictureboxex的Form:Picture1和Picture2(页面是西班牙语,所以我在这里复制修改后的代码):

Dim DY As Single
Dim DX As Single
Dim Flag_MouseMove As Boolean

Private Sub CancelarDrag(Source As Control)
Source.Visible = True
Source.Drag vbCancel
End Sub

Private Sub FinalizarDrag(Source As Control, Button As Integer)
If Button = vbLeftButton Then
Source.Visible = True
Source.ZOrder
Source.Drag vbEndDrag
End If
End Sub

Private Sub IniciarDrag(Source As Control, Button As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
DX = X
DY = Y

Source.Drag vbBeginDrag
Source.Visible = False
Source.Drag
End If
End Sub

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Dim ejeY, ejeX As Single

ejeX = X - 60
ejeY = Y - 60
ejeX = ejeX - DX
ejeY = ejeY - DY

Source.Visible = True
Source.Move ejeX, ejeY
Source.Drag vbEndDrag
Source.ZOrder
End Sub

Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
CancelarDrag Picture1
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
IniciarDrag Picture1, Button, X, Y
Flag_MouseMove = True
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
FinalizarDrag Picture1, Button
Flag_MouseMove = False
End Sub

Private Sub Picture2_DragDrop(Source As Control, X As Single, Y As Single)
CancelarDrag Picture2
End Sub

Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
IniciarDrag Picture2, Button, X, Y
Flag_MouseMove = True
End Sub

Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
FinalizarDrag Picture2, Button
Flag_MouseMove = False
End Sub

代码工作得很好,除非光标位于另一个图片框的区域内,我将移动的图片框放在那里。移动的图片框消失了,直到我重新加载表单才会回来。我怎么能避免这个“图片盒消失”?

vb6 runtime
1个回答
0
投票

我知道了!问题出在“IniciarDrag”功能中。 Source控件必须始终可见,这样可以解决任何问题(比如尝试将控件放在窗体之外!):

Source.Visible = True
© www.soinside.com 2019 - 2024. All rights reserved.