Good day! It is necessary to memorize the position of the form c with a red frame after it is closed. Implemented using the ini file. Loading from file

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"))); 

Upload to file

  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 I kept the position values one

The next time you start the program, the form is here enter image description here

It is possible that this form is a subsidiary and all because of this, tell me the direction!

  • In which event does the data from the Ini file get? - NMD
  • when creating the main form, I launch the function that extracts all this and sets the size of the form with a red frame - user3216530
  • attach the code for creating a form with a red frame and how you specify its position obtained from the ini file - NMD
  • one
    add infoF.StartPosition = FormStartPosition.Manual; before infoF.DesktopLocation = new System.Drawing.Point - NMD

1 answer 1

Initially, the value of the DesktopLocation property was set, which is responsible for the position of the form on the screen

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

but since the value of the StartPosition property of the form was not equal to the value of the FormStartPosition.Manual (tells the form that the window position will be set to manual); values ​​that were specified in the DesktopLocation variable were ignored and replaced with standard Windows values.

It is also worth noting that during testing it was enough to add a string

 infoF.StartPosition = FormStartPosition.Manual; 

in order for the form to be displayed where it was necessary for us, but the documentation says that it is necessary not only to set the StartPosition value in Manual, but also to set the Location value (as did the author of the question.), and not DesktopLocation (I have this option worked properly).

DesktopLocation - Desktop coordinates are based on the working area of ​​the screen, which excludes the taskbar.

Location - Desktop coordinates relative to the top left corner of the monitor.