Domanda

I'm trying to make VB.net program and UI is like normal desktop. 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. i also tryed as a panel and get same result. Edit : pictures about dragging is png , 50x50 , transparent 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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top