Results 1 to 4 of 4

Thread: OnPaint

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

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

  2. #2

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Ohhh....Invalidate()....well who could have guessed that....

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  4. #4

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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
  •  



Click Here to Expand Forum to Full Width