Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flickering Graphics

Status
Not open for further replies.

OmegaSeven

Programmer
Joined
Jun 24, 2003
Messages
2
Location
GB
How do you stop flickering graphics with GDI+, all examples that I found are in C#, none in VB.net.
I think it has sometime to do with "Off Screen DC".

I am trying to create a graphic that looks and acts like a search light, which I've done but it flickers.

Any suggestion / ideas would be greatly appreciated.

Here's my code.
Dim RotationAngle As Integer = 0
Dim myGraphics As Graphics

Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
RotationAngle = Me.TrackBar1.Value
RedrawLight(TrackBar1, New EventArgs())
End Sub

Private Sub RedrawLight(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
myGraphics = CreateGraphics()
myGraphics.Clear(Color.Transparent)
'Erase Previous
Dim path As New GraphicsPath()
path.AddEllipse(100, 100, 50, 500)
Dim pthGrBrush As New PathGradientBrush(path)
pthGrBrush.CenterPoint = New PointF(125, 100)
pthGrBrush.CenterColor = Color.Transparent
Dim Backcolor As Color() = {Color.Transparent}
pthGrBrush.SurroundColors = Backcolor
Dim rotatepoint As New PointF(125.0F, 100.0F)
Dim myMatrix As New Matrix()
myMatrix.RotateAt(RotationAngle, rotatepoint, MatrixOrder.Append)
myGraphics.Transform = myMatrix
myGraphics.FillEllipse(pthGrBrush, 100, 100, 50, 500)
'Paint it
pthGrBrush.CenterColor = Color.SkyBlue
myGraphics.FillEllipse(pthGrBrush, 100, 100, 50, 500)
myGraphics.Dispose()
pthGrBrush.Dispose()
End Sub
 
Good question, I need to know the answer to this too!! The off-screen DC sounds about right, but I can't find any reference to it.
 
Found the answer at last so thought I'd post it here. To stop flickering, create a graphics object from an off-screen bitmap and draw to that - then draw from the off-screen graphics to the form (or whatever). Make sure you clear the off-screen graphics each time you update the drawing - but not the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top