I want to restore the form's size and I used the below codes.
I got an idea from this thread.
And I found out on some machines (in particular, Windows10) a form's width keeps doubled when I reopen this specific form.
I'm guessing that it might be scaling issue of screen resolution but I can't reproduce it.
Since I didn't calculate but store the form's size directly, I have no idea where to look.
I'm going to use a remote assistant and try to figure out why it happened. I will share what I find.
private void Form_Load(object sender, EventArgs e)
{
this.RestoreWindowPosition();
}
private void SaveWindowPosition()
{
Properties.Settings.Default.ReviewFormState = this.WindowState;
if (this.WindowState == FormWindowState.Normal)
{
Properties.Settings.Default.ReviewFormLocation = this.Location;
Properties.Settings.Default.ReviewFormSize = this.Size;
}
else
{
Properties.Settings.Default.ReviewFormLocation = this.RestoreBounds.Location;
Properties.Settings.Default.ReviewFormSize = this.RestoreBounds.Size;
}
Properties.Settings.Default.ReviewFormHasSetDefaults = true;
Properties.Settings.Default.Save();
}
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
this.SaveWindowPosition();
}
private void RestoreWindowPosition()
{
if (Properties.Settings.Default.ReviewFormHasSetDefaults)
{
this.WindowState = Properties.Settings.Default.ReviewFormState;
this.Location = Properties.Settings.Default.ReviewFormLocation;
this.Size = Properties.Settings.Default.ReviewFormSize;
}
}
After a remote session
As I said earlier, I finished a remote session. I found out this is because of a scale issue. But still, it seems pretty strange. I've checked [display settings - scale and layout] menu and it was 125%. Then I open the form and repeat. I found the form size is growing. I think it was 1.25 times on the first try. What I did was I changed the scale on 100%, then did the same thing open and repeat. For this time, I didn't find anything; the form was in the same size.
My middle step conclusion is that I need to save a pure size of the form. I will translate according to the scale. Then I guess, I can get a real size of the form. I'm not really sure I will try and share what I find for letting someone out in the loop.
@Jimi and @Louis Go I hope that one day I can help you too. Thank you for helping me.