-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathForm1.cs
138 lines (115 loc) · 4.25 KB
/
Form1.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
using AppWindowCore;
using Microsoft.UI.Windowing;
using Microsoft.Windows.ApplicationModel.DynamicDependency;
using System;
using System.Drawing;
using System.Windows.Forms;
using Windows.Graphics;
namespace AppWindowsWinForms
{
public partial class Form1 : Form
{
AppWindow appWindow;
public Form1()
{
InitializeComponent();
var success = Bootstrap.TryInitialize(0x00010000, out _);
if (!success)
{
MessageBox.Show("Unable to initialize Windows App SDK - Make sure it's installed");
return;
}
appWindow = this.GetAppWindow();
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
Bootstrap.Shutdown();
}
private void RepositionClick(object sender, EventArgs e)
{
var tag = ((sender as Button).Tag+"").Split(",");
var col = int.Parse(tag[0]);
var row = int.Parse(tag[1]);
appWindow.Reposition(row, col);
}
private void ChangeIconClick(object sender, EventArgs e)
{
appWindow.ChangeIcon("icon1.ico");
}
private void ChangePresenterClick(object sender, EventArgs e)
{
if (Enum.TryParse<AppWindowPresenterKind>((sender as Button).Text.ToString(), out var presenterKind))
{
appWindow.SetPresenter(presenterKind);
}
}
private void OverlappedPresenterPropertyCheckedChanged(object sender, EventArgs e)
{
var presenter = appWindow.Presenter as OverlappedPresenter;
if (presenter is null)
{
return;
}
var check = sender as CheckBox;
var propertyName = check.Text;
var property = typeof(OverlappedPresenter).GetProperty(propertyName);
property.SetValue(presenter, check.Checked);
}
private void OverlappedPresenterTitleBarAndBorderCheckChanged(object sender, EventArgs e)
{
var presenter = appWindow.Presenter as OverlappedPresenter;
if (presenter is null)
{
return;
}
var hasBorder = HasBorderCheckBox.Checked;
var hasTitleBar = HasTitleBarCheckBox.Checked;
presenter.SetBorderAndTitleBar(hasBorder, hasTitleBar);
}
private Random rnd { get; } = new Random();
private Color GetRandomColor()
{
return Color.FromArgb(
(byte)rnd.Next(0, 255),
(byte)rnd.Next(0, 255),
(byte)rnd.Next(0, 255),
(byte)rnd.Next(0, 255));
}
private Windows.UI.Color GetRandomWindowsColor()
{
return Windows.UI.Color.FromArgb(
(byte)rnd.Next(0, 255),
(byte)rnd.Next(0, 255),
(byte)rnd.Next(0, 255),
(byte)rnd.Next(0, 255));
}
private void TitleBarRandomColorClick(object sender, EventArgs e)
{
var property = typeof(AppWindowTitleBar).GetProperty((sender as Button).Text.ToString());
var clr = GetRandomWindowsColor();
property.SetValue(appWindow.TitleBar, clr);
}
private void ChangeIconAndMenuClick(object sender, EventArgs e)
{
if (Enum.TryParse<IconShowOptions>((sender as Button).Text.ToString(), out var showOptions))
{
appWindow.TitleBar.IconShowOptions = showOptions;
}
}
private void ToggleClientAreaChanged(object sender, EventArgs e)
{
appWindow.TitleBar.ExtendsContentIntoTitleBar = (sender as CheckBox).Checked;
}
private void SetDragAreaClick(object sender, EventArgs e)
{
var newHeight = (int)rnd.Next(0, 200);
DragAreaBorder.Height = newHeight;
DragAreaBorder.BackColor = GetRandomColor();
appWindow.TitleBar.SetDragRectangles(new[] {
new RectInt32(0,0,
(int)DragAreaBorder.Width,
(int)newHeight + (appWindow.TitleBar.ExtendsContentIntoTitleBar?0:appWindow.TitleBar.Height)) });
}
}
}