Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WinForm C# program.cs file. It either (a) runs a setup Form1 or (b) loads a setup file. Form1 constructs a default setup file that can be customized and saved as a serialized text setup file. Form1 has a menu item RUN. When that is clicked, Form1 hides itself and runs/shows Form2. When Form2 is exited, it closes itself and shows Form1. All this seems to work fine.

But my problem is that in situation "b", the program file receives the pathname of a setup file to load. After that I want to go immediately to Form2 .. without ever showing Form1. I don't even want Form1 to flicker on, then hide, which is the result of various Web queries/suggestions I found about this or very similar problems.

I try to set a flag in program.cs so that when Form1 runs, it jumps right to the RUN event handler and shows Form2. But Form1 doesn't hide. What happens now is that the program file calls a routine that loads the setup, then Form1 runs, is visible, and displays that setup and then my Form2 runs as well using the loaded setup and both are visible. Form1.Hide() calls seem ignored. Perhaps I should just try running Form2 from program.cs in this case (but it has to return to a Form1 eventually). Thank so for any suggestions of links to clues here.
Posted

As far as I can see this looks like a design issue. You're trying to control the workflow inside the forms which actually are parts of the workflow. Because of this you encounter problems.

What I suggest is that you create a new class which would be responsible for opening and calling the correct form at the correct time. This class should not have any user interface but act only as a controller. The Form1 and Form2 should not know about each other but all the logic should go through the controlling class.

This way the whole workflow can be decided and initiated from any point without having to worry if a form is loaded even if not needed.
 
Share this answer
 
You mean something like the following?

if ( setup file doesn't exist )
{
  run Form 1 to create setup
}

if ( setup file exists )
{
  run Form 2 on setup file
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900