繁体   English   中英

拖动时图片盒/面板撕裂vb.net

[英]Picturebox / Panel tearing when drag vb.net

我正在尝试制作VB.net程序,UI就像普通的桌面一样。 我在图片框中有图像作为桌面快捷方式。 因此,用户可以在窗体中拖动它们。 顺便说一句,我不熟练的刚开始做这样的事情。 我可以通过鼠标事件移动图片框,但是拖动时图片框中的图片会撕裂。 我有一张大背景图片,我想这是问题所在,但我需要帮助才能摆脱眼泪。 继承人代码thx。 我也尝试作为面板,并获得相同的结果。 编辑:有关拖动的图片是png,50x50,透明BG。

Public Class testform
Dim drag As Boolean
Dim mousex, mousey As Integer
Private Sub testform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.BackgroundImage = My.Resources.worldmap 'approx 1.03mb Picture size
End Sub
Private Sub dragbox_MouseDown(sender As Object, e As MouseEventArgs) Handles dragbox.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Left Then
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - dragbox.Left
        mousey = Windows.Forms.Cursor.Position.Y - dragbox.Top
    Else
    End If
End Sub

Private Sub dragbox_MouseMove(sender As Object, e As MouseEventArgs) Handles dragbox.MouseMove
    If drag = True Then
        dragbox.Left = Windows.Forms.Cursor.Position.X - mousex
        dragbox.Top = Windows.Forms.Cursor.Position.Y - mousey
    End If
End Sub

Private Sub dragbox_MouseLeave(sender As Object, e As EventArgs) Handles dragbox.MouseLeave
    drag = False
End Sub

末级

您需要使图像形式双缓冲。 这意味着它将不再撕裂,因为在显示下一帧之前首先要完全确保所有位置都到位。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM