Skip to content

Commit

Permalink
Fix initial window size and remember window pos
Browse files Browse the repository at this point in the history
On startup, set the window's size to a more appropriate value so as not
to see the ugly scrollbars. Also, remember the window's location on
exit and reapply it on startup.

Author's note:

This should not be merged upstream! This is just a hasty custom patch
that I made that works well for my personal setup, where I use it with
my custom profile switcher.

I do not know whether the window size values used here only work well
on my machine, or whether they would also work well for everyone. On my
machine it is pixel perfect, such that the scroll bars don't appear but
it is also not any larger than it needs to be.

Also, for storing the window's location, it may be better to use
GUISettings now (i.e the .config file), rather than what is utilized
here (a .NET user.config file located in %LocalAppData%\grapher).

As I say, I just put this together for my own personal benefit.
  • Loading branch information
strangebit committed Oct 5, 2021
1 parent 2896b8a commit 76d6c4b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 12 deletions.
15 changes: 15 additions & 0 deletions grapher/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="grapher.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<userSettings>
<grapher.Properties.Settings>
<setting name="WindowLocation" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="WindowMaximized" serializeAs="String">
<value>False</value>
</setting>
</grapher.Properties.Settings>
</userSettings>
</configuration>
1 change: 1 addition & 0 deletions grapher/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 27 additions & 6 deletions grapher/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,37 @@ public void ResizeAndCenter()

Size = new Size
{
Width = Math.Min(workingArea.Width, optionsPanel.Size.Width + chartsPreferredSize.Width),
Height = Math.Min(workingArea.Height, chartsPreferredSize.Height + 48)
Width = optionsPanel.Size.Width + chartsPreferredSize.Width + 13,
Height = chartsPreferredSize.Height + 36
};

Location = new Point
Location = Properties.Settings.Default.WindowLocation;

if (Properties.Settings.Default.WindowMaximized)
{
X = workingArea.X + (workingArea.Width - Size.Width) / 2,
Y = workingArea.Y + (workingArea.Height - Size.Height) / 2
};
WindowState = FormWindowState.Maximized;
}
}

private void RawAcceleration_FormClosing(object sender, FormClosingEventArgs e)
{
switch (WindowState)
{
case FormWindowState.Maximized:
Properties.Settings.Default.WindowMaximized = true;
Properties.Settings.Default.WindowLocation = RestoreBounds.Location;
break;
case FormWindowState.Minimized:
Properties.Settings.Default.WindowMaximized = false;
Properties.Settings.Default.WindowLocation = RestoreBounds.Location;
break;
case FormWindowState.Normal:
Properties.Settings.Default.WindowMaximized = false;
Properties.Settings.Default.WindowLocation = Location;
break;
}

Properties.Settings.Default.Save();
}

#endregion Method
Expand Down
30 changes: 30 additions & 0 deletions grapher/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions grapher/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="grapher.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="WindowLocation" Type="System.Drawing.Point" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting>
<Setting Name="WindowMaximized" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 76d6c4b

Please sign in to comment.