Skip to content

Commit 2c9476f

Browse files
committed
Issues #133 Made width and height attributes as optional for windowSizeItems section
1 parent 7d7d475 commit 2c9476f

File tree

7 files changed

+56
-101
lines changed

7 files changed

+56
-101
lines changed

SmartSystemMenu/Forms/MainForm.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,17 @@ private void SysCommand(object sender, SysCommandEventArgs e)
801801
else if (_settings.Sizer == WindowSizerType.WindowWithoutMargins)
802802
{
803803
var margins = window.GetSystemMargins();
804-
window.SetSize(sizeForm.WindowWidth + margins.Left + margins.Right, sizeForm.WindowHeight + margins.Top + margins.Bottom, sizeForm.WindowLeft, sizeForm.WindowTop);
804+
window.SetSize(sizeForm.WindowWidth == null ? null : (sizeForm.WindowWidth + margins.Left + margins.Right),
805+
sizeForm.WindowHeight == null ? null : (sizeForm.WindowHeight + margins.Top + margins.Bottom),
806+
sizeForm.WindowLeft,
807+
sizeForm.WindowTop);
805808
}
806809
else
807810
{
808-
window.SetSize(sizeForm.WindowWidth + (window.Size.Width - window.ClientSize.Width), sizeForm.WindowHeight + (window.Size.Height - window.ClientSize.Height), sizeForm.WindowLeft, sizeForm.WindowTop);
811+
window.SetSize(sizeForm.WindowWidth == null ? null : (sizeForm.WindowWidth + (window.Size.Width - window.ClientSize.Width)),
812+
sizeForm.WindowHeight == null ? null : (sizeForm.WindowHeight + (window.Size.Height - window.ClientSize.Height)),
813+
sizeForm.WindowLeft,
814+
sizeForm.WindowTop);
809815
}
810816

811817
window.Menu.UncheckSizeMenu();
@@ -1165,11 +1171,17 @@ private void SetSizeMenuItem(Window window, int itemId, WindowSizeMenuItem item)
11651171
else if (_settings.Sizer == WindowSizerType.WindowWithoutMargins)
11661172
{
11671173
var margins = window.GetSystemMargins();
1168-
window.SetSize(item.Width + margins.Left + margins.Right, item.Height + margins.Top + margins.Bottom, item.Left, item.Top);
1174+
window.SetSize(item.Width == null ? null : (item.Width + margins.Left + margins.Right),
1175+
item.Height == null ? null : (item.Height + margins.Top + margins.Bottom),
1176+
item.Left,
1177+
item.Top);
11691178
}
11701179
else
11711180
{
1172-
window.SetSize(item.Width + (window.Size.Width - window.ClientSize.Width), item.Height + (window.Size.Height - window.ClientSize.Height), item.Left, item.Top);
1181+
window.SetSize(item.Width == null ? null : (item.Width + (window.Size.Width - window.ClientSize.Width)),
1182+
item.Height == null ? null : (item.Height + (window.Size.Height - window.ClientSize.Height)),
1183+
item.Left,
1184+
item.Top);
11731185
}
11741186
window.Menu.UncheckMenuItems(MenuItemId.SC_ROLLUP);
11751187
}

SmartSystemMenu/Forms/SettingsSizeForm.cs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ private void InitializeControls(LanguageSettings settings, WindowSizeMenuItem me
3535
txtTitle.Text = menuItem.Title;
3636
txtLeft.Text = menuItem.Left == null ? "" : menuItem.Left.Value.ToString();
3737
txtTop.Text = menuItem.Top == null ? "" : menuItem.Top.Value.ToString();
38-
txtWidth.Text = menuItem.Width.ToString();
39-
txtHeight.Text = menuItem.Height.ToString();
38+
txtWidth.Text = menuItem.Width == null ? "" : menuItem.Width.ToString();
39+
txtHeight.Text = menuItem.Height == null ? "" : menuItem.Height.ToString();
4040

4141
cmbKey1.ValueMember = "Id";
4242
cmbKey1.DisplayMember = "Text";
@@ -77,37 +77,10 @@ private void ButtonApplyClick(object sender, EventArgs e)
7777
menuItem.Key2 = (VirtualKeyModifier)cmbKey2.SelectedValue;
7878
menuItem.Key3 = (VirtualKey)cmbKey3.SelectedValue;
7979

80-
if (int.TryParse(txtWidth.Text, out var width))
81-
{
82-
menuItem.Width = width;
83-
}
84-
else
85-
{
86-
txtWidth.SelectAll();
87-
txtWidth.Focus();
88-
return;
89-
}
90-
91-
if (int.TryParse(txtHeight.Text, out var height))
92-
{
93-
menuItem.Height = height;
94-
}
95-
else
96-
{
97-
txtHeight.SelectAll();
98-
txtHeight.Focus();
99-
return;
100-
}
101-
102-
if (int.TryParse(txtLeft.Text, out var left))
103-
{
104-
menuItem.Left = left;
105-
}
106-
107-
if (int.TryParse(txtTop.Text, out var top))
108-
{
109-
menuItem.Top = top;
110-
}
80+
menuItem.Width = int.TryParse(txtWidth.Text, out var width) ? width : null;
81+
menuItem.Height = int.TryParse(txtHeight.Text, out var height) ? height : null;
82+
menuItem.Left = int.TryParse(txtLeft.Text, out var left) ? left : null;
83+
menuItem.Top = int.TryParse(txtTop.Text, out var top) ? top : null;
11184

11285
MenuItem = menuItem;
11386
DialogResult = DialogResult.OK;

SmartSystemMenu/Forms/SizeForm.cs

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace SmartSystemMenu.Forms
77
{
88
partial class SizeForm : Form
99
{
10-
public int WindowLeft { get; private set; }
10+
public int? WindowLeft { get; private set; }
1111

12-
public int WindowTop { get; private set; }
12+
public int? WindowTop { get; private set; }
1313

14-
public int WindowWidth { get; private set; }
14+
public int? WindowWidth { get; private set; }
1515

16-
public int WindowHeight { get; private set; }
16+
public int? WindowHeight { get; private set; }
1717

1818
public SizeForm(Window window, ApplicationSettings settings)
1919
{
@@ -30,59 +30,27 @@ private void InitializeControls(Window window, LanguageSettings settings)
3030
btnApply.Text = settings.GetValue("size_btn_apply");
3131
Text = settings.GetValue("size_form");
3232

33-
var left = window.Size.Left;
34-
var top = window.Size.Top;
35-
var width = window.Size.Width;
36-
var height = window.Size.Height;
33+
var size = window.Size;
3734

38-
WindowLeft = left;
39-
WindowTop = top;
40-
WindowWidth = width;
41-
WindowHeight = height;
35+
WindowLeft = size.Left;
36+
WindowTop = size.Top;
37+
WindowWidth = size.Width;
38+
WindowHeight = size.Height;
4239

43-
txtLeft.Text = left.ToString();
44-
txtTop.Text = top.ToString();
45-
txtWidth.Text = width.ToString();
46-
txtHeight.Text = height.ToString();
40+
txtLeft.Text = size.Left.ToString();
41+
txtTop.Text = size.Top.ToString();
42+
txtWidth.Text = size.Width.ToString();
43+
txtHeight.Text = size.Height.ToString();
4744

4845
DialogResult = DialogResult.Cancel;
4946
}
5047

5148
private void ButtonApplyClick(object sender, EventArgs e)
5249
{
53-
if (!int.TryParse(txtLeft.Text, out var left))
54-
{
55-
txtLeft.SelectAll();
56-
txtLeft.Focus();
57-
return;
58-
}
59-
60-
if (!int.TryParse(txtTop.Text, out var top))
61-
{
62-
txtTop.SelectAll();
63-
txtTop.Focus();
64-
return;
65-
}
66-
67-
if (!int.TryParse(txtWidth.Text, out var width))
68-
{
69-
txtWidth.SelectAll();
70-
txtWidth.Focus();
71-
return;
72-
}
73-
74-
if (!int.TryParse(txtHeight.Text, out var height))
75-
{
76-
txtHeight.SelectAll();
77-
txtHeight.Focus();
78-
return;
79-
}
80-
81-
WindowLeft = left;
82-
WindowTop = top;
83-
WindowWidth = width;
84-
WindowHeight = height;
85-
50+
WindowLeft = int.TryParse(txtLeft.Text, out var left) ? left : null;
51+
WindowTop = int.TryParse(txtTop.Text, out var top) ? top : null;
52+
WindowWidth = int.TryParse(txtWidth.Text, out var width) ? width : null;
53+
WindowHeight = int.TryParse(txtHeight.Text, out var height) ? height : null;
8654
DialogResult = DialogResult.OK;
8755
Close();
8856
}

SmartSystemMenu/Settings/ApplicationSettingsFile.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public static ApplicationSettings Read(string fileName, string languageFileName)
4040
.Select(x => new WindowSizeMenuItem
4141
{
4242
Title = x.Attribute("title") != null ? x.Attribute("title").Value : "",
43-
Left = !string.IsNullOrEmpty(x.Attribute("left").Value) ? int.Parse(x.Attribute("left").Value) : (int?)null,
44-
Top = !string.IsNullOrEmpty(x.Attribute("top").Value) ? int.Parse(x.Attribute("top").Value) : (int?)null,
45-
Width = int.Parse(x.Attribute("width").Value),
46-
Height = int.Parse(x.Attribute("height").Value),
43+
Left = !string.IsNullOrEmpty(x.Attribute("left").Value) ? int.Parse(x.Attribute("left").Value) : null,
44+
Top = !string.IsNullOrEmpty(x.Attribute("top").Value) ? int.Parse(x.Attribute("top").Value) : null,
45+
Width = !string.IsNullOrEmpty(x.Attribute("width").Value) ? int.Parse(x.Attribute("width").Value) : null,
46+
Height = !string.IsNullOrEmpty(x.Attribute("height").Value) ? int.Parse(x.Attribute("height").Value) : null,
4747
Key1 = x.Attribute("key1") != null && !string.IsNullOrEmpty(x.Attribute("key1").Value) ? (VirtualKeyModifier)int.Parse(x.Attribute("key1").Value) : VirtualKeyModifier.None,
4848
Key2 = x.Attribute("key2") != null && !string.IsNullOrEmpty(x.Attribute("key2").Value) ? (VirtualKeyModifier)int.Parse(x.Attribute("key2").Value) : VirtualKeyModifier.None,
4949
Key3 = x.Attribute("key3") != null && !string.IsNullOrEmpty(x.Attribute("key3").Value) ? (VirtualKey)int.Parse(x.Attribute("key3").Value) : VirtualKey.None
@@ -243,8 +243,8 @@ public static void Save(string fileName, ApplicationSettings settings)
243243
new XAttribute("title", x.Title),
244244
new XAttribute("left", x.Left == null ? "" : x.Left.Value.ToString()),
245245
new XAttribute("top", x.Top == null ? "" : x.Top.Value.ToString()),
246-
new XAttribute("width", x.Width),
247-
new XAttribute("height", x.Height),
246+
new XAttribute("width", x.Width == null ? "" : x.Width.ToString()),
247+
new XAttribute("height", x.Height == null ? "" : x.Height.ToString()),
248248
new XAttribute("key1", x.Key1 == VirtualKeyModifier.None ? "" : ((int)x.Key1).ToString()),
249249
new XAttribute("key2", x.Key2 == VirtualKeyModifier.None ? "" : ((int)x.Key2).ToString()),
250250
new XAttribute("key3", x.Key3 == VirtualKey.None ? "" : ((int)x.Key3).ToString())))),

SmartSystemMenu/Settings/WindowSizeMenuItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public class WindowSizeMenuItem : ICloneable
1414

1515
public int? Top { get; set; }
1616

17-
public int Width { get; set; }
17+
public int? Width { get; set; }
1818

19-
public int Height { get; set; }
19+
public int? Height { get; set; }
2020

2121
public VirtualKeyModifier Key1 { get; set; }
2222

@@ -30,8 +30,8 @@ public WindowSizeMenuItem()
3030
Title = "";
3131
Left = null;
3232
Top = null;
33-
Width = 0;
34-
Height = 0;
33+
Width = null;
34+
Height = null;
3535
Key1 = VirtualKeyModifier.None;
3636
Key2 = VirtualKeyModifier.None;
3737
Key3 = VirtualKey.None;
3 KB
Binary file not shown.

SmartSystemMenu/Window.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,18 @@ public void SetHeight(int height)
370370
MoveWindow(Handle, size.Left, size.Top, size.Width, height, true);
371371
}
372372

373-
public void SetSize(int width, int height, int? left = null, int? top = null)
373+
public void SetSize(int? width, int? height, int? left = null, int? top = null)
374374
{
375375
var size = Size;
376376
var sizeLeft = left == null ? size.Left : left.Value;
377-
var sizeTop = top == null ? Size.Top : top.Value;
377+
var sizeTop = top == null ? size.Top : top.Value;
378+
var sizeWidth = width == null ? size.Width : width.Value;
379+
var sizeHeight = height == null ? size.Height : height.Value;
378380
State.Left = sizeLeft;
379381
State.Top = sizeTop;
380-
State.Width = width;
381-
State.Height = height;
382-
MoveWindow(Handle, sizeLeft, sizeTop, width, height, true);
382+
State.Width = sizeWidth;
383+
State.Height = sizeHeight;
384+
MoveWindow(Handle, sizeLeft, sizeTop, sizeWidth, sizeHeight, true);
383385
}
384386

385387
public void RestoreSize()

0 commit comments

Comments
 (0)