473,412 Members | 3,343 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,412 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 1689

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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.