【问题标题】:Picturebox / Panel tearing when drag vb.net拖动时图片框/面板撕裂 vb.net
【发布时间】:2014-05-23 21:18:31
【问题描述】:

我正在尝试制作 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

结束类

【问题讨论】:

    标签: vb.net drag-and-drop panel picturebox tearing


    【解决方案1】:

    您需要使图片表单双缓冲。这意味着它不会再撕裂,因为它会在显示下一帧之前首先完全确保它就位。

    【讨论】:

    • 我真的很想感谢你关于这个 limnic 这解决了我的问题和抱歉迟到的答案 =)
    猜你喜欢
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    相关资源
    最近更新 更多