-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPositionPersister.cs
53 lines (46 loc) · 1.39 KB
/
PositionPersister.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace BetterOutlookReminder
{
using BetterOutlookReminder.Properties;
using System;
using System.Linq;
using System.Windows;
using WpfScreenHelper;
public class PositionPersister
{
private Window window;
private bool loaded;
private bool BoundsAreOnScreen
{
get
{
var bounds = new Rect(Settings.Default.Left, Settings.Default.Top, window.Width, window.Height);
return Screen.AllScreens.Any(s => s.Bounds.Contains(bounds));
}
}
public void Persist(Window window)
{
this.window = window;
window.Activated += form_Load;
window.LocationChanged += form_Save;
form_Load(this, EventArgs.Empty);
}
private void form_Save(object sender, EventArgs e)
{
if (loaded)
{
Settings.Default.Top = window.Top;
Settings.Default.Left = window.Left;
Settings.Default.Save();
}
}
private void form_Load(object sender, EventArgs e)
{
if (BoundsAreOnScreen)
{
window.Top = Settings.Default.Top;
window.Left = Settings.Default.Left;
}
loaded = true;
}
}
}