当我移动并将其放置在运行时的另一个图片框上时,如何避免图片框消失?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当我移动并将其放置在运行时的另一个图片框上时,如何避免图片框消失?相关的知识,希望对你有一定的参考价值。
我测试了这个网页中用于在运行时移动图片框的代码: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
代码工作得很好,除非光标位于另一个图片框的区域内,我将移动的图片框放在那里。移动的图片框消失了,直到我重新加载表单才会回来。我怎么能避免这个“图片盒消失”?
答案
我知道了!问题出在“IniciarDrag”功能中。 Source控件必须始终可见,这样可以解决任何问题(比如尝试将控件放在窗体之外!):
Source.Visible = True
以上是关于当我移动并将其放置在运行时的另一个图片框上时,如何避免图片框消失?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 jquery ui 可拖动突出显示悬停时的可放置区域
如何通过 Amazon EC2 将 postgresql 数据移动到 Ubuntu 上的另一个目录?