回答編集履歴
2
修正
answer
CHANGED
@@ -18,7 +18,6 @@
|
|
18
18
|
$AnchorLeftTopRight = [AnchorStyles]::Left + [AnchorStyles]::Top + [AnchorStyles]::Right
|
19
19
|
|
20
20
|
$This.Controls.Add($This.SplitContainer)
|
21
|
-
|
22
21
|
$This.SplitContainer.Width = $This.ClientSize.Width
|
23
22
|
$This.SplitContainer.Anchor = $AnchorLeftTopRight
|
24
23
|
|
1
追記
answer
CHANGED
@@ -1,1 +1,47 @@
|
|
1
|
-
[Control.FindForm Method](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.control.findform?view=netframework-4.7.2) でそのコントロールの所属するフォームを取得できます。みつかったのは Form 型なので、それを MyForm にキャストすれば TxBox2 が使えると思います。
|
1
|
+
[Control.FindForm Method](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.control.findform?view=netframework-4.7.2) でそのコントロールの所属するフォームを取得できます。みつかったのは Form 型なので、それを MyForm にキャストすれば TxBox2 が使えると思います。
|
2
|
+
|
3
|
+
# 追記
|
4
|
+
|
5
|
+
Form を継承してみました。ついでに Anchor を使うようにしました。
|
6
|
+
|
7
|
+
```ps1
|
8
|
+
Using NameSpace System.Windows.Forms
|
9
|
+
|
10
|
+
Class MyForm : Form
|
11
|
+
{
|
12
|
+
[TextBox] $TxtBox1 = [TextBox]::new()
|
13
|
+
[TextBox] $TxtBox2 = [TextBox]::new()
|
14
|
+
[SplitContainer] $SplitContainer = [SplitContainer]::new()
|
15
|
+
|
16
|
+
MyForm()
|
17
|
+
{
|
18
|
+
$AnchorLeftTopRight = [AnchorStyles]::Left + [AnchorStyles]::Top + [AnchorStyles]::Right
|
19
|
+
|
20
|
+
$This.Controls.Add($This.SplitContainer)
|
21
|
+
|
22
|
+
$This.SplitContainer.Width = $This.ClientSize.Width
|
23
|
+
$This.SplitContainer.Anchor = $AnchorLeftTopRight
|
24
|
+
|
25
|
+
function AddTextBox
|
26
|
+
{
|
27
|
+
Param([Panel]$Panel, [TextBox]$TextBox, [ScriptBlock]$Script)
|
28
|
+
$Panel.Controls.Add($TextBox)
|
29
|
+
$TextBox.Width = $Panel.ClientSize.Width
|
30
|
+
$TextBox.Anchor = $AnchorLeftTopRight
|
31
|
+
$TextBox.Add_TextChanged($Script)
|
32
|
+
}
|
33
|
+
|
34
|
+
AddTextBox $This.SplitContainer.Panel1 $This.TxtBox1 {
|
35
|
+
$This.FindForm().TxtBox2.Text = $This.Text
|
36
|
+
}
|
37
|
+
|
38
|
+
AddTextBox $This.SplitContainer.Panel2 $This.TxtBox2 {
|
39
|
+
$This.FindForm().TxtBox1.Text = $This.Text
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
$Form = [MyForm]::new()
|
45
|
+
|
46
|
+
$Form.ShowDialog()
|
47
|
+
```
|