Ludo_Dirckx
asked on
how to avoid creating same form objects
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.
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.
ASKER
I have to use Closed then
should i use it like
df.Closed += new FormClosedEventHandler(df_ FormClosed );
is it right
should i use it like
df.Closed += new FormClosedEventHandler(df_
is it right
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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.
this.Close();
Main form waits for Closed event and shows itself again.
ASKER
I think i made it.
I had put it in the right place.
It was my mistake.
thanks a lot.
I had put it in the right place.
It was my mistake.
thanks a lot.
ASKER
hi AlexFM,
I got one more question.
How can i refresh the mainform when i show it again
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.
ASKER
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.
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.
df.FormClosed += new FormClosedEventHandler(df_
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.