Check that the button click event is fired: put a breakpoint there and check the handler is added (though adding a handler each time the button is clicked is a bad idea).
The most likely reason for a Paint handler not firing is it isn't hooked up, and that implies that the button event isn't hooked up either, or it's all hooked to the wrong instance of the form.
When you are sure it is attached, check that the PictureBox itself is Invalidated at some point - Paint is only raised when it's needed, it isn't on a timer or anything.
Quote:
Hi OriginalGriff, done it all. The button click is fired, but the paint event is not hit. Invalidate the picturebox doesn't help either.
I'm a bit lost here
All I can say is "it works fine for me":
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Paint += new PaintEventHandler(PictureBox1_Paint);
}
private void PictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(Pens.Green, new Rectangle(5, 5, pictureBox1.Width - 10, pictureBox1.Height - 10));
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Invalidate();
}