Rather than developing an application with numerous frames andhiding/showing them as required, I decided to investigatestar ting my Winform application via a class and using delegatesto decide which form to show as the main form.
Below is a code snipet
class PrerequisiteIns taller
{
private static bool exitApplication = false;
private delegate void OnDialogResultD elegate( );
private static OnDialogResultD elegate currentDelegate = null;
private static System.Drawing. Point formLocation;
public static void Main()
{
currentDelegate = newOnDialogResu ltDelegate(Chec kPrerequesites) ;
formLocation = new System.Drawing. Point(20,20);
while( exitApplication == false )
{
currentDelegate ();
}
System.Diagnost ics.Debug.Write Line("Applicati on exiting");
}
private static void CheckPrerequesi tes()
{
frmCheckPrerequ esites firstForm = newfrmCheckPrer equesites();
firstForm.Locat ion = formLocation;
if ( firstForm.ShowD ialog() ==System.Window s.Forms.DialogR esult.OK )
{
currentDelegate = newOnDialogResu ltDelegate(Chec kServicePacks);
}
else
{
exitApplication = true;
}
formLocation = firstForm.Locat ion;
}
private static void CheckServicePac ks()
{
frmCheckService Packs secondForm = new frmCheckService Packs();
secondForm.Loca tion = formLocation;
if ( secondForm.Show Dialog() ==System.Window s.Forms.DialogR esult.OK )
{
// Move to next screen
}
else
{
System.Diagnost ics.Debug.Write Line("Must deal with thempressing EXIT!!!!!!! in this and all other screens");
currentDelegate = newOnDialogResu ltDelegate(Chec kPrerequesites) ;
}
formLocation = secondForm.Loca tion;
}
}
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.
--------------------------------
From: Stephen Haeney
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>Pnu2DSPIkEq JmRtbYNaUQA==</Id>