S
Stephen Haeney via .NET 247
Rather than developing an application with numerous frames andhiding/showing them as required, I decided to investigatestarting my Winform application via a class and using delegatesto decide which form to show as the main form.
Below is a code snipet
class PrerequisiteInstaller
{
private static bool exitApplication = false;
private delegate void OnDialogResultDelegate( );
private static OnDialogResultDelegate currentDelegate = null;
private static System.Drawing.Point formLocation;
public static void Main()
{
currentDelegate = newOnDialogResultDelegate(CheckPrerequesites);
formLocation = new System.Drawing.Point(20,20);
while( exitApplication == false )
{
currentDelegate();
}
System.Diagnostics.Debug.WriteLine("Application exiting");
}
private static void CheckPrerequesites()
{
frmCheckPrerequesites firstForm = newfrmCheckPrerequesites();
firstForm.Location = formLocation;
if ( firstForm.ShowDialog() ==System.Windows.Forms.DialogResult.OK )
{
currentDelegate = newOnDialogResultDelegate(CheckServicePacks);
}
else
{
exitApplication = true;
}
formLocation = firstForm.Location;
}
private static void CheckServicePacks()
{
frmCheckServicePacks secondForm = new frmCheckServicePacks();
secondForm.Location = formLocation;
if ( secondForm.ShowDialog() ==System.Windows.Forms.DialogResult.OK )
{
// Move to next screen
}
else
{
System.Diagnostics.Debug.WriteLine("Must deal with thempressing EXIT!!!!!!! in this and all other screens");
currentDelegate = newOnDialogResultDelegate(CheckPrerequesites);
}
formLocation = secondForm.Location;
}
}
Using this mechanism, you have to set the window start positionto manual and then save/set it for each new window, or the callto ShowDialog will move the next window to be displayed.
The only problem with this approach is that it seems slow - thewindows flicker between button presses on the forms. Of course,I could implement this using a giant switch statement, based onthe current "state" of the application, but using delegatesseems far more elegant.
Does anyone have any idea why this approach is slow? or is therean easier way to do this?
Thanks.
Below is a code snipet
class PrerequisiteInstaller
{
private static bool exitApplication = false;
private delegate void OnDialogResultDelegate( );
private static OnDialogResultDelegate currentDelegate = null;
private static System.Drawing.Point formLocation;
public static void Main()
{
currentDelegate = newOnDialogResultDelegate(CheckPrerequesites);
formLocation = new System.Drawing.Point(20,20);
while( exitApplication == false )
{
currentDelegate();
}
System.Diagnostics.Debug.WriteLine("Application exiting");
}
private static void CheckPrerequesites()
{
frmCheckPrerequesites firstForm = newfrmCheckPrerequesites();
firstForm.Location = formLocation;
if ( firstForm.ShowDialog() ==System.Windows.Forms.DialogResult.OK )
{
currentDelegate = newOnDialogResultDelegate(CheckServicePacks);
}
else
{
exitApplication = true;
}
formLocation = firstForm.Location;
}
private static void CheckServicePacks()
{
frmCheckServicePacks secondForm = new frmCheckServicePacks();
secondForm.Location = formLocation;
if ( secondForm.ShowDialog() ==System.Windows.Forms.DialogResult.OK )
{
// Move to next screen
}
else
{
System.Diagnostics.Debug.WriteLine("Must deal with thempressing EXIT!!!!!!! in this and all other screens");
currentDelegate = newOnDialogResultDelegate(CheckPrerequesites);
}
formLocation = secondForm.Location;
}
}
Using this mechanism, you have to set the window start positionto manual and then save/set it for each new window, or the callto ShowDialog will move the next window to be displayed.
The only problem with this approach is that it seems slow - thewindows flicker between button presses on the forms. Of course,I could implement this using a giant switch statement, based onthe current "state" of the application, but using delegatesseems far more elegant.
Does anyone have any idea why this approach is slow? or is therean easier way to do this?
Thanks.