Simple enough - I had an application composed of a single form (frmMain) - now for the next version I needed to add a new form (frmFirst) to be displayed first (as sort of a control form).
Instead of displaying frmMain first I want to add a control form (frmFirst) to check and see if the user can proceed to launch the actual application.
I assume this can be done without moving the main() from frmMain to frmFirst (right?)
This is a step-by-step of what I am trying to accomplish:
- Application Starts
- frmFirst is displayed to the user
- if the user presses OK then frmMain is displayed to the user and frmFirst is closed/disposed/hidden (no more need)
- if the user presses CANCEL then the application terminates
So this is the approach I took,
- Start frmMain and immediatly hide it
- Create an instance of frmFirst and show it
- If OK is pressed in frmFrist then display frmMain and dispose of this (frmFirst)
- If CANCEL is pressed the application terminates
Find below sniplets of both frmMain and frmFirst which attempt to perform the above mentioned scheme:
-= frmMain =-
-= frmFirst =-
Oddly enough this is NOT working - I keep getting the following error (on the line of code with the *** above)
Error: Cannot access a disposed object named "frmFirst".
But why exactly? And how do I get around that so to get the desired results?
Also, it seems that the this.Hide() in the frmMain FormLoad does NOT work - when the application loads the form is NOT hidden, any clue why? Is that because you cannot .HIDE() in the form_load (seeing as the form has not yet been loaded)?
If so then how do you immediatly hide the form from the user?
Any help, ideas, or comments would be greatly appreciated - of course any alternative (and better more conventional) ideas would be great (you know if I am going about this the wrong way).
Thanks,
Instead of displaying frmMain first I want to add a control form (frmFirst) to check and see if the user can proceed to launch the actual application.
I assume this can be done without moving the main() from frmMain to frmFirst (right?)
This is a step-by-step of what I am trying to accomplish:
- Application Starts
- frmFirst is displayed to the user
- if the user presses OK then frmMain is displayed to the user and frmFirst is closed/disposed/hidden (no more need)
- if the user presses CANCEL then the application terminates
So this is the approach I took,
- Start frmMain and immediatly hide it
- Create an instance of frmFirst and show it
- If OK is pressed in frmFrist then display frmMain and dispose of this (frmFirst)
- If CANCEL is pressed the application terminates
Find below sniplets of both frmMain and frmFirst which attempt to perform the above mentioned scheme:
-= frmMain =-
Code:
frmFirst fFirst = null;
static void Main()
{
Application.Run(new frmMain());
}
private void frmMain_Load(object sender, System.EventArgs e)
{
this.hide() // this doesn't seem to work?
fFirst = new frmFirst(this);
fFirst.Show();
} // *** oddly enough this is where the ERROR occurs ???? at the end of the form_load???
-= frmFirst =-
Code:
frmMain fMain = null;
public frmFirst(frmMain Main)
{
InitializeComponent();
fMain = Main;
}
private void btnOK_Click(object sender, System.EventArgs e)
{
if (Validate())
{
fMain.Show();
this.Dispose(true);
}
}
Oddly enough this is NOT working - I keep getting the following error (on the line of code with the *** above)
Error: Cannot access a disposed object named "frmFirst".
But why exactly? And how do I get around that so to get the desired results?
Also, it seems that the this.Hide() in the frmMain FormLoad does NOT work - when the application loads the form is NOT hidden, any clue why? Is that because you cannot .HIDE() in the form_load (seeing as the form has not yet been loaded)?
If so then how do you immediatly hide the form from the user?
Any help, ideas, or comments would be greatly appreciated - of course any alternative (and better more conventional) ideas would be great (you know if I am going about this the wrong way).
Thanks,