Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Administrators
Posted

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();

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

Posted

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 =)

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...