sde Posted June 1, 2004 Posted June 1, 2004 I want to fill the background of a form with a Graphics object. 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. Quote codenewbie
Administrators PlausiblyDamp Posted June 1, 2004 Administrators Posted June 1, 2004 You probably want to put that code (or rather the version below) into the form's Paint event. 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(); Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sde Posted June 1, 2004 Author Posted June 1, 2004 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. Quote codenewbie
Administrators PlausiblyDamp Posted June 2, 2004 Administrators Posted June 2, 2004 In the form load event you could try the following lines of code and see if that helps Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) Me.SetStyle(ControlStyles.DoubleBuffer, True) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
sde Posted June 2, 2004 Author Posted June 2, 2004 that's 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 i'm 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 i'm getting this flicker. back to the drawing board =) Quote codenewbie
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.