-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmWaiting.cs
More file actions
117 lines (94 loc) · 3.23 KB
/
frmWaiting.cs
File metadata and controls
117 lines (94 loc) · 3.23 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace GradesAssignment
{
public partial class frmWaiting : Form
{
public const int TimerIntervalInMs = 300;
private static int NextWndID = 1;
/// <summary>
/// Key - id окна
/// </summary>
private readonly static Dictionary<int, frmWaiting> m_dictAllWnds = new Dictionary<int, frmWaiting>();
public int ID { get; }
public bool AllowClose { get; set; } = false;
int m_RemTimersCountForShow = 0;
Point m_OldTL = new Point(0, 0);
System.Windows.Forms.Timer m_tmrSearching = new System.Windows.Forms.Timer() { Interval = TimerIntervalInMs };
public void ClearOwner()
{
Owner = null;
}
public frmWaiting()
{
InitializeComponent();
}
/// <summary>
///
/// </summary>
/// <param name="owner"></param>
/// <param name="ShowingPauseInMs">
/// Через сколько милисекунд отобразиться окно. Нужно задавать значения кратные TimerIntervalInMs
/// </param>
public frmWaiting(Form owner, int ShowingPauseInMs = 0)
{
InitializeComponent();
if (frmMain.Instance != null)
frmMain.Instance.WaitingForm = this;
TopMost = true;
ID = NextWndID++;
Owner = owner;
m_OldTL = new Point(Owner.Location.X + Owner.Size.Width / 2 - Size.Width / 2,
Owner.Location.Y + Owner.Size.Height / 2 - Size.Height / 2);
Location = new Point(10000, 10000);
m_tmrSearching.Tick += (s, ev) =>
{
if (m_RemTimersCountForShow-- == 0)
{
Location = m_OldTL;
try
{
Show();
}
catch
{ }
}
};
m_RemTimersCountForShow = ShowingPauseInMs / (int)Math.Max(1, m_tmrSearching.Interval);
m_tmrSearching.Start();
}
protected override void OnClosing(CancelEventArgs e)
{
e.Cancel = !AllowClose;
if (!e.Cancel)
{
m_tmrSearching.Stop();
m_dictAllWnds.Remove(ID);
}
base.OnClosing(e);
}
protected override void OnClosed(EventArgs e)
{
if (Owner == null || Owner.Handle == IntPtr.Zero)
frmMain.Instance.Activate();
else if (Owner != frmMain.Instance || Owner.Handle == IntPtr.Zero)
{
if (Owner.Handle == IntPtr.Zero)
frmMain.Instance.Activate();
else
Owner.Activate();
}
if (frmMain.Instance != null)
frmMain.Instance.WaitingForm = null;
base.OnClosed(e);
}
}
}