Should I use DrawImage?

  • Thread starter Thread starter Nightmare
  • Start date Start date
N

Nightmare

Guest
Okay...consider these two pieces of code (mousepointing is a point structure given a value outside of the sub):

Code:
Private Sub picPart_QueryContinueDrag(ByVal sender As _
Object, ByVal e As System.Windows.Forms.QueryContinueDragEventArgs)
    dim newlocation as point
        
    newlocation = Me.PointToClient(MousePosition)
    newlocation.X -= mousepointing.X
    newlocation.Y -= mousepointing.Y    
        
    sender.location = newlocation
end sub
AND
Code:
Private Sub picPart_QueryContinueDrag(ByVal sender As _
Object, ByVal e As System.Windows.Forms.QueryContinueDragEventArgs)
    dim newlocation as point

    newlocation = Me.PointToClient(MousePosition)
    newlocation.X -= mousepointing.X
    newlocation.Y -= mousepointing.Y

    CreateGraphics.Clear(Me.BackColor)
    Dim gr As Graphics
    gr = Me.CreateGraphics
    gr.DrawImage(sender.image, newlocation)
end sub

The point of either of these functions is so that I can drag an image around a form with it appearing under the cursor as it is being dragged. Using DrawImage, after I am done dragging I obviously would need to move the picturebox to that location.

As I understand it DrawImage is .NETs equivalent to BitBlt without an API call. However, moving the control around the form with the mouse causes virtually no flicker whereas using DrawImage does (for me anyway).

So which one is more efficient, less memory draining...and which one would you recommend using? Or is there a better method...Im no expert on this stuff...
 
If you look up Double Buffering on drawing graphics, you could avoid the flickering problem.
 
Back
Top