R
rayreeves
If I look for guidance on this topic I find simple examples like this:
public class Form2:Form {
public Form2() {
this.Text = "FORM2";
this.Size = new Size(450,400);
this.Paint += new PaintEventHandler(Draw_Graphics);
}
public void Draw_Graphics(object sender,PaintEventArgs e)
{
Graphics g = e.Graphics;
System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(500, 400);
for(int i = 0; i < 500; i++)
for(int j = 0; j < 50; j++)
bmap.SetPixel(i, j, Color.Red);
g.DrawImage(bmap,200,100);
}
};
static void Main()
{
Application.Run(new Form2());
}
This works as advertised but there is some sly sleight of hand going on
here.
Apparently the Form2 constructor raises a signal that is caught by the
handler Draw_Graphics().
What was the signal and who raised it?
I ask because if I replace the innocuous-looking statement
"Application.Run" by a simple call to the constructor it executes that but
no event is raised and the handler does not run.
What is the dark secret here? What does Application.Run() actually do?
Now I want to run a dialog box first and then perform the above, so I say:
Application.Run(new Form1())
Application.Exit();
Application.Run(new Form2())
No dice! I get Form1 and the Form2 constructor but no signal.
Ray Reeves
public class Form2:Form {
public Form2() {
this.Text = "FORM2";
this.Size = new Size(450,400);
this.Paint += new PaintEventHandler(Draw_Graphics);
}
public void Draw_Graphics(object sender,PaintEventArgs e)
{
Graphics g = e.Graphics;
System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(500, 400);
for(int i = 0; i < 500; i++)
for(int j = 0; j < 50; j++)
bmap.SetPixel(i, j, Color.Red);
g.DrawImage(bmap,200,100);
}
};
static void Main()
{
Application.Run(new Form2());
}
This works as advertised but there is some sly sleight of hand going on
here.
Apparently the Form2 constructor raises a signal that is caught by the
handler Draw_Graphics().
What was the signal and who raised it?
I ask because if I replace the innocuous-looking statement
"Application.Run" by a simple call to the constructor it executes that but
no event is raised and the handler does not run.
What is the dark secret here? What does Application.Run() actually do?
Now I want to run a dialog box first and then perform the above, so I say:
Application.Run(new Form1())
Application.Exit();
Application.Run(new Form2())
No dice! I get Form1 and the Form2 constructor but no signal.
Ray Reeves