I have the following sample code, which I expect to color the panel on the form red as soon as it loads:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
drawstuff();
}
public void drawstuff()
{
using (Graphics g = panel1.CreateGraphics())
{
g.Clear(Color.Red);
}
}
private void button1_Click(object sender, EventArgs e)
{
drawstuff();
}
}
However, for some reason it doesn't draw on the panel when I call my drawstuff()
function from the constructor like that. When I press the button to call drawstuff()
, it works just fine.
Can anyone explain what is happening here?