473,765 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hidden main form, use of delegates etc

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>
Jul 21 '05 #1
2 1709

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*******@dotn et247.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 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 = new OnDialogResultD elegate(CheckPr erequesites);
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 = new frmCheckPrerequ esites();
firstForm.Locat ion = formLocation;
if ( firstForm.ShowD ialog() == System.Windows. Forms.DialogRes ult.OK )
{
currentDelegate = new OnDialogResultD elegate(CheckSe rvicePacks);
}
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.Windows. Forms.DialogRes ult.OK )
{
// Move to next screen
}
else
{
System.Diagnost ics.Debug.Write Line("Must deal with them pressing EXIT!!!!!!!
in this and all other screens");
currentDelegate = new OnDialogResultD elegate(CheckPr erequesites);
}
formLocation = secondForm.Loca tion;
}
}

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>Pnu2DSPIkEq JmRtbYNaUQA==</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*******@dotn et247.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 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 = new OnDialogResultD elegate(CheckPr erequesites);
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 = new frmCheckPrerequ esites();
firstForm.Locat ion = formLocation;
if ( firstForm.ShowD ialog() == System.Windows. Forms.DialogRes ult.OK )
{
currentDelegate = new OnDialogResultD elegate(CheckSe rvicePacks);
}
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.Windows. Forms.DialogRes ult.OK )
{
// Move to next screen
}
else
{
System.Diagnost ics.Debug.Write Line("Must deal with them pressing EXIT!!!!!!!
in this and all other screens");
currentDelegate = new OnDialogResultD elegate(CheckPr erequesites);
}
formLocation = secondForm.Loca tion;
}
}

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>Pnu2DSPIkEq JmRtbYNaUQA==</Id>
Jul 21 '05 #3

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

Similar topics

7
8762
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 function to read the hidden field, but it says the field has no value even though I have a default value in the field. So my question is how do I get PHP to read the value of a hidden field?
2
296
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 some code that will allow the class executing the current DTS package to send back messages to the main form of the application.
0
2510
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), Form2's WndProc method is overriden, if the message is CLOSE message, just hide the form. I first initialize and show the child form, then close it by clicking the Close(X) button, the overriden WndProc method gets invoked, and the form is hidden. Then
2
1952
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 hidden vars and does the database operation. Seems straight forward enough but I have run into a few stumbling blocks including submitting then closing the popup and reverting control back to the main form to pick up the variables. Someone has to...
4
3584
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 quite tiresome to have to write code to call MyControl.Invoke for each control on the form, along with the delegates that are required for each. Is there a better way to do this? What I mean is, if I could marshal the
1
1909
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 Form1. So far so good.
2
379
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 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...
7
3441
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 eventing code is slightly hidden. when you use events in Vb.Net you type this: <code> Public event MyEvent() </code>
3
4846
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 pointers (delegates). I assume I need to use the array< T keyword to allocate an array of delegates, and then initialize the array by setting each array element to the pointers (handles) of the functions I'll be invoking. I've been trying to...
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.