我试图制作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
结束班
答案 0 :(得分:1)
您需要使图片形式为双缓冲。这意味着它将不再撕裂,因为它会在显示下一帧之前首先完全确保它全部到位。