I am new to the .NET compact framework (and a lot of new for C #), and I had a problem with switching forms in a mobile application. At a high level, my application uses several forms with the main class "application manager", which performs navigation / switching between forms. My plan was to create forms on demand, cache them and use a simple hide / show strategy.
At first I wanted to do something like the following in my main application class:
public void switchForm(Form newForm) { currentForm.Hide();
However, this did not work as planned. The new form I was trying to show appeared very temporarily and then disappeared behind the main form of my application - any ideas as to why this is happening? I read quite a lot when switching form, and most places seemed to mention that the above method was a way to do this.
Then I tried the following:
public void switchForm(Form newForm) { currentForm.Hide();
and that seems to do the trick. I wonder, however, is this the right way? However, using the ShowDialog () method creates another problem. Let's say I want to get rid of the old form, for example:
public void switchForm(Form newForm) { Form oldForm = currentForm; currentForm = newForm; newForm.ShowDialog(); oldForm.Dispose(); }
Then I found out that the code of oldForm.Dispose () is not executed until the execution of newForm.ShowDialog () is complete (the form is closed). Therefore, the foregoing can lead to leaks when the forms are not correctly placed, since the method is called again and again during the transition to new forms. Another way is to first discard the old form before showing the new one, then my application temporarily displays something else (regardless of the form) between the old form that will be deleted and the new rendered: / How should I go? something like this?
Many thanks.
source share