-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormLocationEditor.cs
91 lines (81 loc) · 2.69 KB
/
FormLocationEditor.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using EDTracking;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SRVTracker
{
public partial class FormLocationEditor : Form
{
private static FormLocationEditor _formInstance = null;
private static Point _formLocation;
public FormLocationEditor()
{
InitializeComponent();
locationManager1.SelectionChanged += LocationManager1_SelectionChanged;
}
public static FormLocationEditor GetFormLocationEditor()
{
if (_formInstance == null || _formInstance.IsDisposed)
{
_formInstance = new FormLocationEditor();
if (_formLocation != null)
_formInstance.Location = _formLocation;
}
return _formInstance;
}
private void LocationManager1_SelectionChanged(object sender, EventArgs e)
{
if (locationManager1.AllowSelectionOnly)
{
DialogResult = DialogResult.OK;
Hide();
}
}
public EDLocation SelectLocation(IWin32Window parent, Point? windowBottomLeft = null)
{
Point previousWindowLocation = this.Location;
bool wasVisible = false;
if (this.Visible)
{
this.Hide();
wasVisible = true;
}
this.FormBorderStyle = FormBorderStyle.None;
locationManager1.AllowSelectionOnly = true;
if (windowBottomLeft != null)
{
Point windowTopLeft = (Point)windowBottomLeft;
windowTopLeft.Y -= this.Height;
Location = (Point)windowTopLeft;
}
locationManager1.ClearSelection();
DialogResult result = this.ShowDialog(parent);
if (wasVisible)
{
this.Location = previousWindowLocation;
ShowWithBorder();
}
if (result == DialogResult.Cancel)
return null;
return locationManager1.SelectedLocation;
}
public void ShowWithBorder(IWin32Window owner = null)
{
if (this.Visible)
this.Hide();
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
locationManager1.AllowSelectionOnly = false;
this.Show(owner);
}
private void FormLocationEditor_FormClosing(object sender, FormClosingEventArgs e)
{
_formLocation = this.Location;
}
}
}