3
Answers

Graphics - conceptual question

Gary Fritz

Gary Fritz

15y
3.3k
1
I have some basic confusions on how to do graphics in C# (and presumably other .Net languages).  I'm still fairly new to the .Net event-driven model so I'm a little unclear how I should make everything work together. 

I understand that the Paint method draws your form.  I believe that the Paint object is invoked anytime the form needs to be refreshed -- like if you just uncovered the window, or something like that.

But what if I've got a happily displayed form, and now I need to change the content dynamically?  I'm writing a simple game with a board and pieces, and I want to do some animation on the board when the user makes a move.  I've got the board displaying just fine, but I'm not sure how to do the animation.

The Paint method gets called with an object and a PaintEventArgs as params.  You use the PaintEventArgs to create a Graphics object and draw using that.  (That's what I've figured out so far, anyway.  Please feel free to correct any misunderstandings, and if you know of a good source to learn the architecture, I'd love a pointer!!)

So that works for the Paint method.  But what about other code that doesn't get passed the PaintEventArgs param?  How do I create a Graphics object that can talk to the form to do the animation?

The animation operation will happen when the user clicks on the screen, so maybe I should trigger a graphics operation from the Click event handler?

Thanks,
Gary
Answers (3)
Next Recommended Forum