Juliano Posted October 3, 2003 Posted October 3, 2003 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. Quote
aewarnick Posted October 3, 2003 Posted October 3, 2003 You aren't overriding OnPaint and using e to paint with. You don't need CreateGraphics. Quote C#
*Experts* Volte Posted October 3, 2003 *Experts* Posted October 3, 2003 Also, I believe you need to set the styles in the constructor, not in the Load event. Quote
Hamburger1984 Posted October 4, 2003 Posted October 4, 2003 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 Quote
aewarnick Posted October 4, 2003 Posted October 4, 2003 Store your tick value and Box size Rectangle value in global variables at the top of the Form, below the Form class. Quote C#
ThePentiumGuy Posted October 4, 2003 Posted October 4, 2003 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) Quote 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
aewarnick Posted October 4, 2003 Posted October 4, 2003 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. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.