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 7931115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:37:47+00:00 2026-06-03T20:37:47+00:00

I have 2 monitors and I need to save form position and it should

  • 0

I have 2 monitors and I need to save form position and it should show on screen where it was closed.

Can someone suggest how to get screen on which it is, and on form load show it on screen where form was closed?

The settings I save in registry.

  • 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-03T20:37:48+00:00Added an answer on June 3, 2026 at 8:37 pm

    The simplest way is to call the GetWindowPlacement function. That returns a WINDOWPLACEMENT structure that contains information about the window’s on-screen coordinates.

    Using this function instead of the Form.Location property solves the problems you’ll experience with multiple monitors, minimized windows, strangely positioned taskbars, etc.

    The route of attack would be to call the GetWindowPlacement function when your application is shutting down, persist the location of the window to the registry (or wherever you are storing it—the registry is no longer the recommended place for saving application state), and then when your application is re-opened, calling the corresponding SetWindowPlacement function to restore the window to its previous position.

    Since these are native functions exposed by the Win32 API, and you’re working in C#, you’ll need to call them via P/Invoke. Here are the required definitions (for organizational purposes, I recommend placing these in a static class named NativeMethods):

    [StructLayout(LayoutKind.Sequential)]
    struct POINT
    {
        public int X;
        public int Y;
    }
    
    [StructLayout(LayoutKind.Sequential)]
    struct RECT
    {
        public int left;
        public int top;
        public int right;
        public int bottom;
    }
    
    [Serializable]
    [StructLayout(LayoutKind.Sequential)]
    struct WINDOWPLACEMENT
    {
         public int length;
         public int flags;
         public int showCmd;
         public POINT ptMinPosition;
         public POINT ptMaxPosition;
         public RECT rcNormalPosition; 
    }
    
    [DllImport("user32", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
    
    [DllImport("user32", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
    

    To get the current position of your window (which you would do when your app is closing), use this code:

    WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
    wp.length = Marshal.SizeOf(wp);
    GetWindowPlacement(MyForm.Handle, ref wp);
    

    Recall that I mentioned the registry is no longer the recommended place for persisting application state. Since you’re developing in .NET, you have much more powerful and versatile options available. And since the WINDOWPLACEMENT class declared above is marked [Serializable], it would be very easy to serialize this information to your application settings, and then reload it the next time you open.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have developed an MVC3 application which monitors when users access static content on the
i have a WCF service which Monitors a Particular Drive and Creates a New
I have written a windows service, which monitors a database table for pending jobs
I have a scenario which I think I can convey giving PC Monitor example
I have a VB app that I need to monitor while it is running.
I have two different-sized monitors, connected together using (I believe) TwinView. I tried System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
I have a service monitor app that monitors the status of three other servers
I have some Linux code that monitors our hardware by collecting temperatures, voltages, and
I'm writing an app that monitors the user's location. I have a CLLocationManager object
I want to make an application in C or C++ which have to monitor

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.