OmegaSeven
Programmer
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
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