-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAutoSizeForm.cs
221 lines (207 loc) · 6.28 KB
/
AutoSizeForm.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace P4EXP
{
public class AutoSizeForm : Form
{
protected string PreferenceKey {get; set;}
private void SaveControlSettings(Control.ControlCollection Controls)
{
foreach (Control c in Controls)
{
if (c is DoubleBufferedListView)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
((DoubleBufferedListView)c).OnClose(listKey);
}
else if (c is TreeListView)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
((TreeListView)c).OnClose(listKey);
}
else if (c is FilterComboBox)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
((FilterComboBox)c).OnClose(listKey);
}
else if (c is SplitContainer)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
if (PreferenceKey != null && ((SplitContainer) c).SplitterDistance != 0)
{
//Preferences.LocalSettings[listKey + "_SplitterDistance"] =
// ((SplitContainer) c).SplitterDistance;
}
}
//else if (c is P4ToolWindowControlBase)
//{
// ((P4ToolWindowControlBase)c).SaveControlSettings();
//}
if ((c.Controls != null) && (c.Controls.Count > 0))
{
SaveControlSettings(c.Controls);
}
}
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
if (PreferenceKey != null)
{
//Preferences.LocalSettings[PreferenceKey + "_Width"] = Width;
//Preferences.LocalSettings[PreferenceKey + "_Height"] = Height;
//Preferences.LocalSettings[PreferenceKey + "_Top"] = Top;
//Preferences.LocalSettings[PreferenceKey + "_Left"] = Left;
SaveControlSettings(Controls);
}
base.OnClosing(e);
}
private void InitControlSettings(Control.ControlCollection Controls)
{
foreach (Control c in Controls)
{
if (c is DoubleBufferedListView)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
((DoubleBufferedListView)c).OnLoad(listKey);
}
else if (c is TreeListView)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
((TreeListView)c).OnLoad(listKey);
}
else if (c is FilterComboBox)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
((FilterComboBox)c).OnLoad(listKey);
}
else if (c is SplitContainer)
{
string listKey =
string.Format("{0}_{1}", PreferenceKey, c.Name);
//if (listKey != null && Preferences.LocalSettings.ContainsKey(listKey + "_SplitterDistance"))
//{
// ((SplitContainer)c).SplitterDistance =
// (int)Preferences.LocalSettings[listKey + "_SplitterDistance"];
//}
}
//else if (c is P4ToolWindowControlBase)
//{
// ((P4ToolWindowControlBase)c).Initialize();
//}
if ((c.Controls != null) && (c.Controls.Count > 0))
{
InitControlSettings(c.Controls);
}
}
}
protected override void OnLoad(EventArgs e)
{
if (PreferenceKey != null)
{
//int width = Preferences.LocalSettings.GetInt(PreferenceKey + "_Width", -1);
//int height = Preferences.LocalSettings.GetInt(PreferenceKey + "_Height", -1);
//int top = Preferences.LocalSettings.GetInt(PreferenceKey + "_Top", -1);
//int left = Preferences.LocalSettings.GetInt(PreferenceKey + "_Left", -1);
//int minY = SystemInformation.VirtualScreen.Top;
//int minX = SystemInformation.VirtualScreen.Left;
//if ((Width > 0) && (Height > 0) && (top > minY) && (left > minX))
//{
// int maxY = SystemInformation.VirtualScreen.Height;
// int maxX = SystemInformation.VirtualScreen.Width;
// if (width > maxX)
// {
// width = maxX;
// }
// if (height > maxY)
// {
// height = maxY;
// }
// if (((top + height) > maxY) || ((left + width) > maxX))
// {
// StartPosition = FormStartPosition.CenterParent;
// }
// else
// {
// //top left corner of the dialog is visible on the screen
// StartPosition = FormStartPosition.Manual;
// Top = top;
// Left = left;
// Width = width;
// Height = height;
// }
//}
//else
//{
// StartPosition = FormStartPosition.CenterParent;
//}
foreach (Control c in Controls)
{
if (c is I18nControls.GridLayoutPanel)
{
I18nControls.GridLayoutPanel pnl = c as I18nControls.GridLayoutPanel;
pnl.InitializeLayout();
}
}
InitControlSettings(Controls);
}
// Handle by the dialog class, so don't need this
//if (this.AutoSize)
//{
// int maxWidth = 0;
// int maxHeight = 0;
// foreach (Control c in Controls)
// {
// if (c.Right > maxWidth)
// {
// maxWidth = c.Right;
// }
// if (c.Bottom < maxHeight)
// {
// maxHeight = c.Bottom;
// }
// }
// System.Drawing.Size newSize = new System.Drawing.Size(Size.Width, Size.Height);
// bool sizeSet = false;
// if (Size.Height < maxHeight)
// {
// newSize.Height = maxHeight;
// sizeSet = true;
// }
// if (Size.Width < maxWidth)
// {
// newSize.Width = maxWidth;
// sizeSet = true;
// }
// if (this.AutoSizeMode == System.Windows.Forms.AutoSizeMode.GrowAndShrink)
// {
// if (Size.Height > maxHeight)
// {
// newSize.Height = maxHeight;
// sizeSet = true;
// }
// if (Size.Width > maxWidth)
// {
// newSize.Width = maxWidth;
// sizeSet = true;
// }
// }
// if (sizeSet == true)
// {
// this.Size = newSize;
// }
//}
base.OnLoad(e);
}
public System.Drawing.SizeF ScaleFactor { get { return base.AutoScaleFactor; } }
}
}