Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to avoid creating same form objects

Posted on 2006-06-12
9
Medium Priority
?
205 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 1000 total points
ID: 16884997
df.Closed += new EventHandler(df_Closed);

void df_Closed(object sender, EventArgs e)
{
     this.Show();
}
0
Industry Leaders: 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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