-
Notifications
You must be signed in to change notification settings - Fork 18
/
Program.cs
103 lines (86 loc) · 3.79 KB
/
Program.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
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Drawing;
using WInterop;
using WInterop.Gdi;
using WInterop.Windows;
using WInterop.Windows.Classes;
namespace Controls;
internal class Program
{
[STAThread]
private static void Main()
{
Windows.Run(new EditWindow("Edit control"));
}
private class EditWindow : Window
{
private readonly ReplaceableLayout _replaceableLayout;
private readonly EditControl _editControl;
private readonly ButtonControl _buttonControl;
private readonly StaticControl _staticControl;
private readonly TextLabelControl _textLabel;
public EditWindow(string title) : base(
new WindowClass(),
Windows.DefaultBounds,
text: title,
style: WindowStyles.OverlappedWindow,
isMainWindow: true)
{
_editControl = new EditControl(
Windows.DefaultBounds,
editStyle: EditStyles.Multiline | EditStyles.Left
| EditStyles.AutoHorizontalScroll | EditStyles.AutoVerticalScroll,
style: WindowStyles.Child | WindowStyles.Visible | WindowStyles.HorizontalScroll
| WindowStyles.VerticalScroll | WindowStyles.Border,
parentWindow: this);
_buttonControl = new ButtonControl(
Windows.DefaultBounds,
text: "Push Me",
style: WindowStyles.Child | WindowStyles.Visible,
parentWindow: this);
_staticControl = new StaticControl(
Windows.DefaultBounds,
text: "You pushed it!",
style: WindowStyles.Child | WindowStyles.Visible,
parentWindow: this);
_textLabel = new TextLabelControl(
Windows.DefaultBounds,
text: "Text Label Control",
style: WindowStyles.Child | WindowStyles.Visible,
parentWindow: this);
var font = _staticControl.GetFont().GetLogicalFont();
_staticControl.SetWindowText($"{font.FaceName.CreateString()} {font.Quality}");
//this.SetLayout(Layout.FixedSize(new (200, 400), _editControl));
//this.SetLayout(
// Layout.Margin(10, Layout.FixedPercent
// (new (.6f, .4f), _editControl, VerticalAlignment.Top, HorizontalAlignment.Left)));
//this.SetLayout(Layout.Horizontal(
// (.5f, Layout.Margin(5, Layout.Fill(_editControl))),
// (.5f, Layout.Empty)));
_replaceableLayout = new ReplaceableLayout(_textLabel);
this.AddLayoutHandler(Layout.Vertical(
(.5f, Layout.Margin((5, 5, 0, 0), Layout.Fill(_editControl))),
(.5f, Layout.Horizontal(
(.7f, Layout.FixedPercent(.4f, _replaceableLayout)),
(.3f, Layout.FixedPercent(.5f, _buttonControl))))));
MouseHandler handler = new(_buttonControl);
handler.MouseUp += Handler_MouseUp;
}
private void Handler_MouseUp(object sender, WindowHandle window, Point position, Button button, MouseKey mouseState)
{
if (_replaceableLayout.Handler == _staticControl)
{
_staticControl.ShowWindow(ShowWindowCommand.Hide);
_textLabel.ShowWindow(ShowWindowCommand.Show);
_replaceableLayout.Handler = _textLabel;
}
else
{
_replaceableLayout.Handler = _staticControl;
_textLabel.ShowWindow(ShowWindowCommand.Hide);
_staticControl.ShowWindow(ShowWindowCommand.Show);
}
}
}
}