Solved

how to avoid creating same form objects

Posted on 2006-06-12
9
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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