We help IT Professionals succeed at work.

how to avoid creating same form objects

Ludo_Dirckx asked
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);

then if i want to come back to the main form again  i say in the datail form

EKS_comsy.MainForm mf=new MainForm();

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.
Watch Question

EKS_comsy.detailFrom df=new detailForm(orderNr);
df.FormClosed += new FormClosedEventHandler(df_FormClosed);

void df_FormClosed(object sender, FormClosedEventArgs e)

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


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

is it right
This one is on us!
(Get your first solution completely free - no credit card required)


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();

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.

You need to remove all code related to main form from details form. If details form is closed by button, use only

Main form waits for Closed event and shows itself again.


I think i made it.
I had put it in the right place.
It was my mistake.
thanks a lot.


hi AlexFM,
I got one more question.
How can i refresh the mainform when i show it again

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.


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.


Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.