Moving reactangle without flickering?

Spiro

Member
Joined
Feb 5, 2003
Messages
15
Location
Croatia
Hi, I have problem with DragDrop. I trying to move reactangle along with te cursor.
Code:
Private Graphic as Graphics= Panel1.CreateGraphics

Private Sub Panel1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles frm.DragOver
Dim NewP = New Point(e.x,e.y)
Dim rec As New Drawing.Rectangle(NewP, SelCtl.Size)
Graphic.Clear(frm.BackColor)
Graphic.DrawRectangle(Penk, rec)
end sub

How can i simulate Flip method from DDraw to avoid flickering?
 
Youll have to take advantage of the build-in double buffering, which on the face of it is quite easy but youll have to do a bit of work in this instance to get it working.

Firstly, youll have to inherit from Panel and use your own control instead, because you need to use the protected function SetStyle to enable Double Buffering and other associated styles. Then youll have to give that control some kind of property for setting where the rectangle should be drawn.

Finally, in the DragOver event, instead of drawing you set the rectangle property and call .Invalidate on the control, forcing it to draw itself. Double buffering in Windows Forms only works when the control draws itself in the Paint event.
 
Back
Top