I have a class which inherits the Panel Control, whose purpose is to allow me to draw some simple geometrical figures on a transparent background. The object is defined as follows:
public class TrackOverlay : Panel
{
private ControlWindow parentForm;
...
public TrackOverlay(PictureBox parent)
{
parentForm = (ControlWindow)(parent.Parent);
// Create a transparent form on top of <parent>
...
this.Size = parent.ClientSize;
this.Location = parent.PointToScreen(Point.Empty);
parent.Parent.Controls.Add(this);
}
When a certain event occurs (in the context of a BackgroundWorker, if that matters) I call the Invalidate method, and expect to enter the following overridden Paint method, defined as follows:
new private void Paint(object sender, PaintEventArgs e)
{
using (Graphics graphics = this.CreateGraphics())
{
// do graphics stuff
}
}
Using the debugger, I see that Invalidate() is called, but Paint() is not This seems to be similar to the situation described here, but none of the suggestions mentioned there helped me. Following this post I redefined the function signature as follows:
protected override void OnPaint(PaintEventArgs e)
But still no joy. How can I make the event handler happen?