|
-
Nov 23rd, 2004, 05:50 AM
#1
OnPaint
I have a problem here. Something I don't understand.
Well isn't OnPaint only called when there is something to paint? But how can you paint something when you don't have the PaintEventArgs. Well this is my OnPint right now. And I need it to be called every time I have moved the ojects on the screen:
Code:
protected override void OnPaint(PaintEventArgs e)
{
// Set the atributes for the graphics object
g = e.Graphics;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
// Draw a circle
g.FillRectangle( new SolidBrush(Color.Black), ClientRectangle);
g.DrawString("Solsystem", new Font("Courier",32), new SolidBrush(Color.DarkRed), 10,10);
foreach (Himmellegeme spaceObject in skyObjects)
spaceObject.draw(g);
But as you see in the last line, I have to call my draw function and pass it the g (the Graphics object to be able to use FillElipse and DrawString.
Code:
public override void draw(Graphics g) {
g.FillEllipse(new SolidBrush(farge),(float)xpos,(float)ypos,radius*2,radius*2);
g.DrawString(name, new Font("Courier",8), new SolidBrush(Color.White),origox+avstand,origoy+radius);
}
How am I supposed to think here?
Last edited by NoteMe; Nov 23rd, 2004 at 07:03 AM.
-
Nov 23rd, 2004, 07:03 AM
#2
Ohhh....Invalidate()....well who could have guessed that....
-
Nov 23rd, 2004, 07:04 AM
#3
Or, use the CreateGraphics method of your form/control to get a reference to a valid Graphics object.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 23rd, 2004, 07:11 AM
#4
Thanks will look that up to for the next time I need this. This is just a trial and error project to test all the weird ways of doing stuff.
So far I have covered:
- Objects
- Inheritence
- Delegates
- Timer
- Form
- OnPaint
hmmm where to go now....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|