Solved

how to avoid creating same form objects

Posted on 2006-06-12
9
201 Views
Last Modified: 2010-04-16
Hello Experts,
I am busy with visual c# project on win mobile 2003 se.

I have a main form which sync with the server through web service and get the recent list of orders.

for this action I call another class syncDB and that class do the synchronization and writes the records locally.

The process is going fine.

When I want to go to the detail form to see the details I do the main form hide and show the detail form like bellow.

// MainForm.cs

EKS_comsy.detailFrom df=new detailForm(orderNr);
df.Show();
this.Hide();

then if i want to come back to the main form again  i say in the datail form
//detailForm.cs

EKS_comsy.MainForm mf=new MainForm();
mf.Show();
this.Close();

Here i am creating a new object of the main form it initalize all the elements before it come there.  How can i avoid this problem and call the form that i have already. The way i use the code now makes the preformence of the program very low.

Can anyone help me to solve this issue.

thanks in advance.
0
Comment
Question by:Ludo_Dirckx
  • 5
  • 4
9 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16884839
EKS_comsy.detailFrom df=new detailForm(orderNr);
df.FormClosed += new FormClosedEventHandler(df_FormClosed);
this.Hide();
df.Show();


void df_FormClosed(object sender, FormClosedEventArgs e)
{
     this.Show();
}

For C# version before 8.0 use Closed event instead of FormClosed.
0
 

Author Comment

by:Ludo_Dirckx
ID: 16884966
I have to use Closed then
should i use it like
df.Closed += new FormClosedEventHandler(df_FormClosed);

is it right
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 16884997
df.Closed += new EventHandler(df_Closed);

void df_Closed(object sender, EventArgs e)
{
     this.Show();
}
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Ludo_Dirckx
ID: 16885102
The code you wrot is working fine.
Now in the detailForm should i remove the new main form command.

EKS_comsy.MainForm mf=new MainForm();
mf.Show();


i removed the command above in the detailForm.
When i click the  back to main form button the program just quit itself.

What went wrong.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16885200
You need to remove all code related to main form from details form. If details form is closed by button, use only
this.Close();

Main form waits for Closed event and shows itself again.
0
 

Author Comment

by:Ludo_Dirckx
ID: 16885205
I think i made it.
I had put it in the right place.
It was my mistake.
thanks a lot.
0
 

Author Comment

by:Ludo_Dirckx
ID: 16885661
hi AlexFM,
I got one more question.
How can i refresh the mainform when i show it again
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16885846
I don't know what is "Refresh" in your program, this is application-specific. In any case, you can add this code to df_Closed function, after this.Show line.
0
 

Author Comment

by:Ludo_Dirckx
ID: 16886048
No it is ok.
I have a timere wihich refreh the form and every 2 minutes i refresh the mainForm to whow the new records.
It is ok.
It was not related to the df_Closed.


thanks.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question