Results 1 to 11 of 11

Thread: You want to remove Graphics Flicker ?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    49

    You want to remove Graphics Flicker ?

    I hate the thing what they did to Autoredraw on Controls & Forms...so i did a class that stops the object while it's painting in that way, the flicker is reduced, try it.

    This is the class

    Code:
    Public Class IAutoRedraw
        Event AutoRedraw(ByVal g As System.Drawing.Graphics)
    
        Public Sub DoRedraw(ByVal g As System.Drawing.Graphics)
            Dim bDrawing As Boolean
    
            bDrawing = True
            While bDrawing
                RaiseEvent AutoRedraw(g)
                bDrawing = False
            End While
        End Sub
    End Class
    -----------------------------

    This is how to use it:

    Code:
    	Private Withevents IA as New IAutoRedraw
    
    	Private Sub IA_AutoRedraw(ByVal g As System.Drawing.Graphics) Handles IA.AutoRedraw
    		'Do all your graphics stuff here
    	End Sub
    
    	'To use "Almost" FlickerFree Drawing, use: IA.DoRedraw
    	'You can put in the Paint Event of you form, or anything.

    Thank you, [KeLi F.K.A Zleepy].

    Homepage: http://fraxionsoftware.cjb.net
    ICQ: 40269591
    Mail: [email protected]

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Hmm. I'm not quite sure how thats supposed to remove graphics flicker. I tried your method in the following code (it moves a small bitmap in C:\vbtest.bmp around with the pointer) and I got the same flickering as if I wasn't even using your class.

    Code:
        Public bmMyPic As New Bitmap("C:\vbtest.bmp")
        Public gFrm As Graphics
        Public intLastX As Integer
        Public intLastY As Integer
        Private WithEvents IA As New IAutoRedraw()
    
        Private Sub IA_AutoRedraw(ByVal g As System.Drawing.Graphics) Handles IA.AutoRedraw
    
            gFrm.Clear(Color.Gray)
            gFrm.DrawImage(bmMyPic, intLastX, intLastY)
    
        End Sub
    
        Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Me.Width = 640
            Me.Height = 480
            gFrm = Me.CreateGraphics()
    
        End Sub
    
        Private Sub Form2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    
            intLastX = e.X
            intlasty = e.Y
            IA.DoRedraw(gFrm)
    
        End Sub
    
        'To use "Almost" FlickerFree Drawing, use: IA.DoRedraw
        'You can put in the Paint Event of you form, or anything
    
    End Class
    I realize that its the gFrm.Clear() method that causes the flicker. However, for drawing animations like this, you have to call the Clear method. I have found a way to use a backbuffer for drawing graphics, which does get rid of flicker. Again, it moves a bitmap in C:\Vbtest.bmp around the form.

    Code:
        Public bmMyPic As New Bitmap("C:\vbtest.bmp")
        Public bmBackBuffer As Bitmap
        Public gBackBuffer As Graphics
        Public gFrm As Graphics
    
        Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            bmBackBuffer = New Bitmap(640, 480)
    
            Me.Width = 640
            Me.Height = 480
    
            gBackBuffer = Graphics.FromImage(bmBackBuffer)
            gFrm = Me.CreateGraphics()
    
        End Sub
    
        Public Sub RenderScene()
    
            gFrm.DrawImage(bmBackBuffer, 0, 0)
    
        End Sub
    
        Private Sub Form3_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    
            gBackBuffer.Clear(Color.Gray)
            gBackBuffer.DrawImage(bmMyPic, e.X, e.Y)
            RenderScene()
    
        End Sub

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    a lot of times enabling double buffering helps to remove flicker, completely. Put this in your from then redraw everything in the Paint event.

    VB Code:
    1. setstyle(ControlStyles.UserPaint, True)
    2.         setstyle(ControlStyles.AllPaintingInWmPaint, True)
    3.         setstyle(ControlStyles.DoubleBuffer, True)
    4.  
    5. 'in the paint event....
    6.       e.graphics.dowhatever

    If it's a picture that's not gunno change, you can just draw it directly to the form's bg image and you wont need to redraw the image ( ie, if you declare a graphics object by doing Graphics.FromImage(form.backgroundimage) and then you draw on that, you wont need to redraw on it. but if you do form.CreateGraphics() and you draw on that, then you'll need to redraw)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Registered User
    Join Date
    Aug 2017
    Posts
    1

    Smile Re: You want to remove Graphics Flicker ?

    You do not need to draw any controls. just copy the below code to anywhere in the form class preferably just above the end class and flicker will not be visible:

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
    Dim cp As CreateParams = MyBase.CreateParams
    cp.ExStyle = cp.ExStyle Or &H2000000
    Return cp
    End Get
    End Property

    This is for VB.net only

    Happy Learning

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: You want to remove Graphics Flicker ?

    Quote Originally Posted by arimaknp View Post
    You do not need to draw any controls. just copy the below code to anywhere in the form class preferably just above the end class and flicker will not be visible:

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
    Dim cp As CreateParams = MyBase.CreateParams
    cp.ExStyle = cp.ExStyle Or &H2000000
    Return cp
    End Get
    End Property

    This is for VB.net only

    Happy Learning
    You do realize you've just revived a 16 year old thread??? I often stop for a moment to think about my answers, but 16 year thinking time is ridiculous

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: You want to remove Graphics Flicker ?

    Quote Originally Posted by .paul. View Post
    You do realize you've just revived a 16 year old thread??? I often stop for a moment to think about my answers, but 16 year thinking time is ridiculous
    Be fair, Paul, it's only 15 years old.
    P.S. you just flunked Arithmetic 1.

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: You want to remove Graphics Flicker ?

    Ok, you got me. I looked at the Joined date instead of the thread date...

  8. #8
    Addicted Member
    Join Date
    Aug 2017
    Location
    South Africa (in the middle)
    Posts
    160

    Re: You want to remove Graphics Flicker ?

    ...and what version of VS.net did you get in 2002? VB6 is came out later...
    Programmers are very patient people....while programming....but don't expect them to be patient all the time

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: You want to remove Graphics Flicker ?

    Quote Originally Posted by Inside View Post
    ...and what version of VS.net did you get in 2002? VB6 is came out later...
    VB6 was released in 1998, and the first proper release of .Net was VS 2002 (which included VB 7.0), but some of us had the .Net beta about a year earlier.

  10. #10
    New Member
    Join Date
    Jul 2022
    Posts
    6

    Re: You want to remove Graphics Flicker ?

    Nice thanks for the reply dude!

    Its crazy that this tread was created 20 years ago!

  11. #11
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    585

    Re: You want to remove Graphics Flicker ?

    Quote Originally Posted by jamesfalcon23 View Post
    Nice thanks for the reply dude!

    Its crazy that this tread was created 20 years ago!
    What's crazy is bumping this old thread back to the top, thanking a 5 year old reply as if it was written to you, after you joined VBForums yesterday.
    Last edited by Peter Porter; Jul 9th, 2022 at 04:53 PM.

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