I have a very simple WinForm with the following code...When I run it I get stackOverflowException.
When I debug, I see that the OnPaint() method is called dozens of times. But I have nothing (no controls) on the form yet. This is a plain blank form...
namespace
SampleGraphics
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void OnPaint(object sender, PaintEventArgs e)
{
// Obtain a Graphics object from the incoming PaintEventArgs.
Graphics g = e.Graphics;
// Render a textual message in a given font and color.
g.DrawString(
"Hello GDI+", new Font("Times New Roman", 20), Brushes.Green, 0, 0);
// If overriding the Paint method, be sure to call the base class implementation.
base.OnPaint(e);
}
}
}