Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I´m trying to draw a rectangle, for example, in a Form.

I do the following:

 

public graphic as Graphics

 

in the Form_Load I do:

 

graphic = Me.CreateGraphics

Me.SetStyle(ControlStyles.DoubleBuffer, True)

Me.SetStyle(ControlStyles.UserPaint, True)

Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

 

in the Timer_Tick I do:

 

For i = 0 to 100

graphic.Clear(Color.White)

graphic.FillRectangle(Brushes.Blue, 0, 0, 50, 50)

Next

 

I want the rectangle to move without flickering the image, but I can´t avoid the flickering.

 

What am I doing wrong?

 

thanks,

Juliano.

Posted

you should move all your drawing-code into the OnPaint override - like aewarnick said - and use e.Graphics there... in the Timer_Tick-Event you then simply do a "Me.Invalidate()" to tell the Form to redraw... should be flicker-free now...

 

Andreas

Posted
Also, I believe you need to set the styles in the constructor, not in the Load event.

 

actually, you can store the styles in the load event, (i dunno, it seems to work for me when i do that)

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted

That makes sense...only becasue when using SetStyle you have the choice of whether you want it set or not using the bool value.

 

I am pretty sure then that you can switch DoubleBuffing on and off any time you want.

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...