473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Hidden main form, use of delegates etc

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.
--------------------------------
From: Stephen Haeney

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Pnu2DSPIkEqJmRtbYNaUQA==</Id>
Jul 21 '05 #1
2 1686

I use a similar solution using delegates to control the flow of pages in a
wizard dialog. Each page is actually a usercontrol displayed on the form. My
User Process Interface class uses delegates to create/destroy the
usercontrols as required.

An immediate workaround for you would be to change to that approach - have
just one placeholder form and re-create your other forms as usercontrols.

"Stephen Haeney via .NET 247" <an*******@dotnet247.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Rather than developing an application with numerous frames and
hiding/showing them as required, I decided to investigate starting my
Winform application via a class and using delegates to 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 = new OnDialogResultDelegate(CheckPrerequesites);
formLocation = new System.Drawing.Point(20,20);
while( exitApplication == false )
{
currentDelegate();
}
System.Diagnostics.Debug.WriteLine("Application exiting");
}

private static void CheckPrerequesites()
{
frmCheckPrerequesites firstForm = new frmCheckPrerequesites();
firstForm.Location = formLocation;
if ( firstForm.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
currentDelegate = new OnDialogResultDelegate(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 them pressing EXIT!!!!!!!
in this and all other screens");
currentDelegate = new OnDialogResultDelegate(CheckPrerequesites);
}
formLocation = secondForm.Location;
}
}

Using this mechanism, you have to set the window start position to manual
and then save/set it for each new window, or the call to ShowDialog will
move the next window to be displayed.

The only problem with this approach is that it seems slow - the windows
flicker between button presses on the forms. Of course, I could implement
this using a giant switch statement, based on the current "state" of the
application, but using delegates seems far more elegant.

Does anyone have any idea why this approach is slow? or is there an easier
way to do this?

Thanks.
--------------------------------
From: Stephen Haeney

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Pnu2DSPIkEqJmRtbYNaUQA==</Id>
Jul 21 '05 #2

I use a similar solution using delegates to control the flow of pages in a
wizard dialog. Each page is actually a usercontrol displayed on the form. My
User Process Interface class uses delegates to create/destroy the
usercontrols as required.

An immediate workaround for you would be to change to that approach - have
just one placeholder form and re-create your other forms as usercontrols.

"Stephen Haeney via .NET 247" <an*******@dotnet247.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Rather than developing an application with numerous frames and
hiding/showing them as required, I decided to investigate starting my
Winform application via a class and using delegates to 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 = new OnDialogResultDelegate(CheckPrerequesites);
formLocation = new System.Drawing.Point(20,20);
while( exitApplication == false )
{
currentDelegate();
}
System.Diagnostics.Debug.WriteLine("Application exiting");
}

private static void CheckPrerequesites()
{
frmCheckPrerequesites firstForm = new frmCheckPrerequesites();
firstForm.Location = formLocation;
if ( firstForm.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
currentDelegate = new OnDialogResultDelegate(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 them pressing EXIT!!!!!!!
in this and all other screens");
currentDelegate = new OnDialogResultDelegate(CheckPrerequesites);
}
formLocation = secondForm.Location;
}
}

Using this mechanism, you have to set the window start position to manual
and then save/set it for each new window, or the call to ShowDialog will
move the next window to be displayed.

The only problem with this approach is that it seems slow - the windows
flicker between button presses on the forms. Of course, I could implement
this using a giant switch statement, based on the current "state" of the
application, but using delegates seems far more elegant.

Does anyone have any idea why this approach is slow? or is there an easier
way to do this?

Thanks.
--------------------------------
From: Stephen Haeney

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>Pnu2DSPIkEqJmRtbYNaUQA==</Id>
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: bass-man | last post by:
I am trying to include a dynamically changeable file in my website with PHP and Javascript so I am using a hidden field to hold the name of the file I want to include, and I am using the$_GET...
2
by: Chris | last post by:
Hi, I have an application that contains a class library as another project. The application basically executes DTS packages on a remote SQL Server. This works great. However I want to add...
0
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form),...
2
by: aaa | last post by:
I am bringing up a popup which has a couple of fields that the user enters. I fill the hidden fields then submit and close the popup which then reverts back to my main form, which retrieves the...
4
by: Charles Law | last post by:
Hi guys. I have two threads: a main thread and a background thread. Lots of stuff happens in the background thread that means I have to update several (lots) of controls on a form. It is...
1
by: Richard | last post by:
Hello there, I have a form that is called from a Sub Main procedure using application.run(Form1). On my main form there is a button to open an instance of Form2 and then at the same time hide...
2
by: Stephen Haeney via .NET 247 | last post by:
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...
7
by: sam.m.gardiner | last post by:
I'm working with VB.NET events and I want a way to disconnect all the handlers of an event. I want to do this in the object that is the source of the event. This is slightly tricky in VB.Net as the...
3
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.