简体   繁体   English

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

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

I'm trying to make VB.net program and UI is like normal desktop. 我正在尝试制作VB.net程序,UI就像普通的桌面一样。 I have images in picture boxes as desktop shortcuts. 我在图片框中有图像作为桌面快捷方式。 So user can drag them around in form. 因此,用户可以在窗体中拖动它们。 Btw im not skilled just started to do things like this. 顺便说一句,我不熟练的刚开始做这样的事情。 I can move picture boxes with mouse events its fine But pictures in pictureboxes are tearing when dragging. 我可以通过鼠标事件移动图片框,但是拖动时图片框中的图片会撕裂。 i have a big background picture, i guess this is the problem but i need help to get rid of tearing. 我有一张大背景图片,我想这是问题所在,但我需要帮助才能摆脱眼泪。 heres code thx. 继承人代码thx。 i also tryed as a panel and get same result. 我也尝试作为面板,并获得相同的结果。 Edit : pictures about dragging is png , 50x50 , transparent BG. 编辑:有关拖动的图片是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

End Class 末级

You need to make the picture form double buffered. 您需要使图像形式双缓冲。 That means that it will no longer tear as it will first completely make sure it's all in place before showing the next frame. 这意味着它将不再撕裂,因为在显示下一帧之前首先要完全确保所有位置都到位。

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

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