Results 1 to 10 of 10

Thread: [RESOLVED] GDI+ Flickering Problem

Threaded View

  1. #1

    Thread Starter
    Addicted Member mouse88's Avatar
    Join Date
    Mar 2009
    Location
    South Wales, United Kingdom
    Posts
    225

    Resolved [RESOLVED] GDI+ Flickering Problem

    I am having problems with flickering when drawing squares to a picture box. Heres my main form code:

    Code:
    Public Class FrmGame
    
        Public ArrayBlocks(15, 30) As Block
        Public BlockSize As New Size(15, 15)
    
        Private Sub FrmGame_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            'Reduce Flicker'
            SetStyle(ControlStyles.DoubleBuffer, True)
            SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    
        End Sub
    
        Private Sub FrmGame_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    
            'Draw Game Board To Picture Box'
            Dim GameBoard As New GameBoard
            GameBoard.Draw(ImgMain.Handle)
    
    
            'Draw First Line Of Blocks To Picture Box'
            Dim X As Integer
            Dim Color1 As Color = Color.Blue
            Dim Color2 As Color = Color.LightBlue
            Dim InitialLoc As New Point(0, 0)
    
            For X = 0 To 14
    
                ArrayBlocks(X, 0) = New Block(BlockSize, InitialLoc, Color1, Color2)
                ArrayBlocks(X, 0).Draw(ImgMain.Handle)
    
                'Update Initial Location'
                InitialLoc.X += 15
    
                'Change Block Colors'
                If Color1 = Color.Blue And Color2 = Color.LightBlue Then
    
                    Color1 = Color.Red
                    Color2 = Color.Yellow
    
                Else
    
                    Color1 = Color.Blue
                    Color2 = Color.LightBlue
    
                End If
    
            Next X
    
            Me.Invalidate()
    
        End Sub
    
    End Class
    The Rectangle which is my game board is drawn as per normal no flickering, however when the 15 blocks/squares are drawn they are all flickering for some reason. I may be doing something wrong as until now i've been creating basic games with picture boxes. If anyone has any advice i would appreciate it greatly.

    I have also attached a picture of the outcome of what i'm drawing.
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width