Graphics on the back of a form

sde

Well-known member
Joined
Aug 28, 2003
Messages
160
Location
us.ca.fullerton
I want to fill the background of a form with a Graphics object.
Code:
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(myBrush, new Rectangle(0,0,200,300));
myBrush.Dispose();
formGraphics.Dispose();
I got that code directly from the msdn site, but when i compile, it does not show anything.

Ideally what I want to do with a background, is making a gradient twirl. =) just trying to get into it to see what I can do.
 
You probably want to put that code (or rather the version below) into the forms Paint event.
C#:
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = e.Graphics;
formGraphics.FillEllipse(myBrush, new Rectangle(0,0,200,300));
myBrush.Dispose();
 
thanks that works.

i want to change the colors every 10 millisecond.

what would be the smoothest way to keep redrawing a gradient? i can do with the background color of the form, and have a new thread updating the background color so it morphs slowly through the color wheel, .. but gradients seem to require a Refresh() which makes the screen flicker.
 
In the form load event you could try the following lines of code and see if that helps

Code:
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
 
thats pretty cool, .. i see how it make it refresh on its own a lot quicker, .. but still, that is a lot slower than what i need it to refresh at.

the function works great when im dragging another window over the top of this test app , as it refreshes a lot on its own.

it seems like the flicker is caused by a combination of repainting the screen and making the new gradient.

maybe i need to look into directx for something like this to flow smoothely. solid colors seem to work just fine when i just change the background property of the form and i iterate from 0-255 for each rgb value with a Thread.Sleep(1) command in between. It makes for a very nice color shifting effect.

it is when i use the Graphics in combination with the gradient fill that im getting this flicker.

back to the drawing board =)
 
Back
Top