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

  • SEARCH
  • Home
  • 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 7973561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:08:23+00:00 2026-06-04T08:08:23+00:00

This is such a mundane issue I thought I could fix it immediately, but

  • 0

This is such a mundane issue I thought I could fix it immediately, but no.
My form size and location are saved in app settings on exit for restore next time the app is run. If the user closes the form while it is minimized I am having trouble restoring to normal state. The form restores as minimized, and clicking on the taskbar button does nothing. I save the location and size in FormClosing event, but if the form is minimized I am saving the minimized size (160, 40) and location (-32000, -32000), which is totally incorrect for restoring the form. I want to force the form to never restore minimized, but to it’s last normal size and location. Somehow I must capture the size and location before the form is minimized and save that, and then on FormClosing do not save size and location if the form is minimized. This is all probably not 100% clear, but I hope someone has some insight on this.

FormClosing handler:

    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        Settings.Default.WindowLocation = Location;
        Settings.Default.WindowSize = Size;
        Settings.Default.WindowState = WindowState;
        Settings.Default.Save();
    }

Restoring code:

    private void RestoreWindow()
    {
        Location = Settings.Default.WindowLocation;
        if(Location.X == 0 && Location.Y == 0)
            StartPosition = FormStartPosition.CenterScreen;

        Size = Settings.Default.WindowSize;

        WindowState = FormWindowState.Normal;

        if(Size.Width > Screen.PrimaryScreen.WorkingArea.Width)
        {
            Location = new Point(0, Location.Y);
            Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Size.Height);
        }

        if(Size.Height > Screen.PrimaryScreen.WorkingArea.Height)
        {
            Location = new Point(Location.X, 0);
            Size = new Size(Size.Width, Screen.PrimaryScreen.WorkingArea.Height);
        }
    }
  • 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-06-04T08:08:25+00:00Added an answer on June 4, 2026 at 8:08 am

    You shouldn’t save the Location or Size of your form if it isn’t in the normal state:

    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
      if (this.WindowState == FormWindowState.Normal) {
        Settings.Default.WindowLocation = Location;
        Settings.Default.WindowSize = Size;
      }
      Settings.Default.WindowState = WindowState;
      Settings.Default.Save();
    }
    

    Your Restore window routine doesn’t make complete sense. Why save the location if you are centering the form? Starting a program in Minimized mode is probably undesirable, in which case, I would default it to Normal:

    private void RestoreWindow()
    {
      this.Location = Settings.Default.WindowLocation;
      this.Size = Settings.Default.WindowSize;
    
      // check for size or location off-screen, etc.
    
      if ((FormWindowState)Settings.Default.WindowState == FormWindowState.Minimized)
        this.WindowState = FormWindowState.Normal;
      else
        this.WindowState = Settings.Default.WindowState;
    }
    

    If you need to restore the last normal position the window was in, then you can use the OnResizeEnd override to save the settings:

    protected override void OnResizeEnd(EventArgs e) {
      if (this.WindowState == FormWindowState.Normal) {
        Properties.Settings.Default.Location = this.Location;
        Properties.Settings.Default.Size = this.Size;
      }
      base.OnResizeEnd(e);
    }
    

    Then your closing event is just:

    protected override void OnFormClosing(FormClosingEventArgs e) {
      Properties.Settings.Default.WindowState = this.WindowState;
      Properties.Settings.Default.Save();
      base.OnFormClosing(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is such a simple problem, but I can't find an answer anywhere... I
sorry this is such a simple question but I can't figure it out. How
this must be such a simple problem but can someone tell me why this
I'd like to extend Application in my Android app. I've done this such that
How can I write this in such a way that $counter value is 1
Is there a way to make a class such this one: class DB extends
I know this question has been discussed before, and I know this is such
I have a Listview, such this: <ListView ItemsSource={Binding ...} > <ListView.ItemContainerStyle> <Style TargetType=ListViewItem> <Setter
This seems like such a simple question. I have several Edit boxes on my
In an interface such as this: @interface MyClass : NSObject { bool PlainOldBool; }

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.