How do you keep the position of the subsidiary shape?



  • The shape of the red frame must be remembered after its closure.

    Implemented with a .ini file. File download:

        infoF.Width = Convert.ToInt32(ini.GetValue("Settings", "infoWidth"));
        infoF.Height = Convert.ToInt32(ini.GetValue("Settings", "infoHeight"));
        infoF.DesktopLocation = new System.Drawing.Point(Convert.ToInt32(ini.GetValue("Settings", "infoLocationX")), Convert.ToInt32(ini.GetValue("Settings", "infoLocationY")));
    

    File download

       private void info_FormClosing(object sender, FormClosingEventArgs e)
        {
            IniStructure ini = new IniStructure();
    
        ini = IniStructure.ReadIni(Application.StartupPath.ToString() + "\\Temp\\" + "conf.ini");
    
        ini.ModifyValue("Settings", "infoWidth", Width.ToString());
        ini.ModifyValue("Settings", "infoHeight", Height.ToString());
        ini.ModifyValue("Settings", "infoLocationX", this.DesktopLocation.X.ToString());
        ini.ModifyValue("Settings", "infoLocationY", this.DesktopLocation.Y.ToString());
    
        IniStructure.WriteIni(ini, Application.StartupPath.ToString() + "\\Temp\\" + "conf.ini");
    }
    

    But the point remains:

    1

    In the next launch of the program, the form is somehow here:

    введите сюда описание изображения

    It's possible that this form is a daughter-in-law, and that's why, tell me the direction.



  • DesktopLocation was which is responsible for the shape position on the screen

    infoF.DesktopLocation = new System.Drawing.Point(Convert.ToInt32(ini.GetValue("Settings", "infoLocationX")), Convert.ToInt32(ini.GetValue("Settings", "infoLocationY")));
    

    but so on the meaning of the properties StartPosition The shape was equal to that of the shape FormStartPosition. Manual (spoke in the form that the window position will be placed in manual) values as indicated in the variable DesktopLocation were ignored and replaced by Windows standard values.

    It is also worth mentioning that the test provided sufficient addition to the line

    infoF.StartPosition = FormStartPosition.Manual;
    

    For the shape to be displayed where we needed it, but in https://msdn.microsoft.com/ru-ru/library/system.windows.forms.form.startposition(v=vs.110).aspx It is said that it is necessary not only to establish the meaning of StartPosition in the Manual, but also to give the meaning of Location (as the author of the question.) rather than DesktopLocation (this option was correct).

    DesktopLocation - The coordinates of the working table are based on the work area of the screen, which excludes the panel of tasks.

    Location - Coordinates of the working table on the upper left corner of the monitor.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2