|
-
Nov 8th, 2002, 06:41 AM
#1
Thread Starter
Member
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.
-
Nov 8th, 2002, 12:53 PM
#2
Hyperactive Member
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
-
Nov 8th, 2002, 05:08 PM
#3
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:
setstyle(ControlStyles.UserPaint, True)
setstyle(ControlStyles.AllPaintingInWmPaint, True)
setstyle(ControlStyles.DoubleBuffer, True)
'in the paint event....
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!!
-
Aug 25th, 2017, 02:09 AM
#4
Registered User
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
-
Aug 25th, 2017, 06:36 PM
#5
Re: You want to remove Graphics Flicker ?
 Originally Posted by arimaknp
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 26th, 2017, 11:13 AM
#6
Re: You want to remove Graphics Flicker ?
 Originally Posted by .paul.
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.
-
Aug 26th, 2017, 11:57 AM
#7
Re: You want to remove Graphics Flicker ?
Ok, you got me. I looked at the Joined date instead of the thread date...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 29th, 2017, 12:07 AM
#8
Addicted Member
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 
-
Aug 30th, 2017, 06:51 AM
#9
Re: You want to remove Graphics Flicker ?
 Originally Posted by Inside
...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.
-
Jul 9th, 2022, 11:58 AM
#10
New Member
Re: You want to remove Graphics Flicker ?
Nice thanks for the reply dude!
Its crazy that this tread was created 20 years ago!
-
Jul 9th, 2022, 12:17 PM
#11
Re: You want to remove Graphics Flicker ?
 Originally Posted by jamesfalcon23
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|