Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:29:14+00:00 2026-05-14T22:29:14+00:00

I’m new to the .NET compact framework (and pretty much new to C# as

  • 0

I’m new to the .NET compact framework (and pretty much new to C# as well) and I’ve got a problem with switching forms in my mobile application. At a high level, my application makes use of multiple forms, with a main “application manager” class which performs the navigation/switching between the 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(); // instance member
    newForm.Show();
    currentForm = newForm;
}

However, this did not work out as planned. The new form that I was attempting to show, appeared very temporarily and then disappeared behind the main form of my application – any ideas as to why this happens? I’ve done quite a bit of reading on form switching, and most places seemed to mention that the above method was the way to do it.

I then tried out the following:

public void switchForm(Form newForm)
{
    currentForm.Hide(); // instance member
    currentForm = newForm;
    newForm.ShowDialog();
}

and this seems to do the trick. I’m wondering, however, is this the right way to go about it? Using the ShowDialog() method, however, poses another problem. Say I want to dispose of the old form, like so:

public void switchForm(Form newForm)
{
    Form oldForm = currentForm;
    currentForm = newForm;
    newForm.ShowDialog();
    oldForm.Dispose();
}

I then found out that the oldForm.Dispose() code does not execute until the newForm.ShowDialog() completes (the form is closed). Therefore, the above can lead to leaks with the forms not being disposed correctly as the method is called over and over again while moving to new forms. Another way is to dispose the old form first before showing the new one, however, then my application temporarily renders something else (whatever was behind the forms) between the old form being disposed and the new one being rendered :/ How should one go about doing something like this?

Thanks very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:29:14+00:00Added an answer on May 14, 2026 at 10:29 pm

    Try this:

    public void switchForm(Form newForm) 
    { 
        Form oldForm = currentForm
        newForm.Show(); 
        currentForm.Hide();
        currentForm = newForm;
        oldForm.Dispose(); 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.