Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
Override Paint Method for a PaintBox
Chris Bertrand
17y
6.1k
1
Reply
Hi,
I am trying to write a program where multiple instances of a class will draw themselves onto a PictureBox. (If there is a better control to use then that would be useful to know!). The paint method in the main form looks like :
public
virtual
void
pbWorld_Paint(
object
sender, System.Windows.Forms.PaintEventArgs e)
{...
The override in the class of which multiple instances will occur is :
public
override
void
pbWorld_Paint(
object
sender, System.Windows.Forms.PaintEventArgs e)
{
// Create a local version of the graphics object for the PictureBox.
Graphics g = e.Graphics;
System.Drawing.Pen pen =
new
Pen(System.Drawing.Color.Black, 1);
g.DrawRectangle(pen, posX, posY, 2, 2);
}
What I need the program to do is, everytime a new instance is created, update the main PictureBox with the new object, and then everytime the position of that object changes, update the area around the object (so as not to redraw the whole screen). I assume that I need to create a specific event for this and link it to the overridden paint method?!
I hope I have included enough info here - if not, just let me know what else you need to know to help me out on this one!
Many thanks,
Bertie.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
need Help on building a GeometryApplication
Simple questions: Placing Pixels on a form