Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
move formsettings, merge autopositionedform into glucoseform
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjorn committed Aug 24, 2016
1 parent 856d493 commit 4faf363
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 293 deletions.
122 changes: 0 additions & 122 deletions FloatingGlucose/AutoPositionedForm.cs

This file was deleted.

120 changes: 0 additions & 120 deletions FloatingGlucose/AutoPositionedForm.resx

This file was deleted.

2 changes: 1 addition & 1 deletion FloatingGlucose/FloatingGlucose.Designer.cs

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

63 changes: 58 additions & 5 deletions FloatingGlucose/FloatingGlucose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
using System.Globalization;
using FloatingGlucose.Classes.Pebble;
using static FloatingGlucose.Properties.Settings;
using FloatingGlucose.Properties;
using FloatingGlucose.Classes.Extensions;
using Microsoft.Win32;
using FormSettings = FloatingGlucose.Properties.FormSettings;

namespace FloatingGlucose
{

public partial class FloatingGlucose : AutoPositionedForm
public partial class FloatingGlucose : Form//AutoPositionedForm
{

//nightscout URL, will be used to create a pebble endpoint to fetch data from
private string nsURL {
get {

//AlarmUrgentLow
// With raw glucose display we need to have two
// data points to calculate raw glucose diff
Expand Down Expand Up @@ -86,7 +87,27 @@ private void setScaling(float scale) {
public FloatingGlucose()
{
InitializeComponent();

this.StartPosition = FormStartPosition.Manual;

// check if the saved bounds are nonzero and visible on any screen
if (FormSettings.Default.WindowPosition != Rectangle.Empty &&
IsVisibleOnAnyScreen(FormSettings.Default.WindowPosition))
{
// first set the bounds
var pos = FormSettings.Default.WindowPosition;

this.Location = pos.Location;



}
else
{
//position at bottom right per FormSettings.Default
var r = Screen.PrimaryScreen.WorkingArea;
this.Location = new Point(r.Width - this.Width, r.Height - this.Height);

}

}

Expand All @@ -98,7 +119,7 @@ private void setFormSize() {
// Also is used the labels own font size to determine the widths
// So the formula doesn't have to be updated if the label fonts are changed
// during design-time.



var rawbg = TextRenderer.MeasureText("999.0" , this.lblRawBG.Font);
Expand Down Expand Up @@ -360,8 +381,40 @@ static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
// Add your session lock "handling" code here
}

private bool IsVisibleOnAnyScreen(Rectangle rect)
{
foreach (Screen screen in Screen.AllScreens)
{
if (screen.WorkingArea.IntersectsWith(rect))
{
return true;
}
}

return false;
}

public void SaveWindowPosition()
{
if (this.WindowState == FormWindowState.Normal)
{
FormSettings.Default.WindowPosition = this.DesktopBounds;
}
else
{
FormSettings.Default.WindowPosition = this.RestoreBounds;
}


FormSettings.Default.Save();

}



private void FloatingGlucose_Load(object sender, EventArgs e)
{

// We want all data values to be formatted with a dot, not comma, as some cultures do
// as this messes up the gui a bit
// we avoid this: double foo=7.0; foo.toString() => "7,0" in the nb-NO culture
Expand Down Expand Up @@ -411,7 +464,7 @@ private void FloatingGlucose_Load(object sender, EventArgs e)
refreshGlucoseTimer.Tick += new EventHandler((asender, ev)=> LoadGlucoseValue());
refreshGlucoseTimer.Start();



}
private bool Settings_Changed_Event() {
Expand Down
Loading

0 comments on commit 4faf363

Please sign in to comment.