I’m making a small simple windows application. This is my main function:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// This will be my Form object
Form1 robotPath = new Form1();
Application.Run(robotPath);
// at this point I'll try to make changes to my object
// for instance I'll try to change a background image
robotPath.changeImage();
}
However after changing my object, the changes are not reflected in the output window (the background is not changed). I’ve tried robotPath.refresh() and robotPath.invalidate() but still the background is not changing. However, when I call the changeImage function using a button click event it works. But I want it to be changed without using a button/mouse event.(Background changes as the Form1 object is changed)
Any suggestion?
does not return until the main form is closed. All code that runs after
Application.Run()does not run until the program is shutting down. That’s clearly not what you want.You can solve the problem easily enough by reordering your
main:An alternative would be to move the call to
changeImageinto the constructor ofForm1, or some event that fires early in the form’s life, e.g.Load. This option better encapsulates the behaviour of the form.