回答編集履歴

2

修正

2019/02/01 05:44

投稿

Zuishin
Zuishin

スコア28660

test CHANGED
@@ -37,8 +37,6 @@
37
37
 
38
38
 
39
39
  $This.Controls.Add($This.SplitContainer)
40
-
41
-
42
40
 
43
41
  $This.SplitContainer.Width = $This.ClientSize.Width
44
42
 

1

追記

2019/02/01 05:44

投稿

Zuishin
Zuishin

スコア28660

test CHANGED
@@ -1 +1,93 @@
1
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
+ # 追記
6
+
7
+
8
+
9
+ Form を継承してみました。ついでに Anchor を使うようにしました。
10
+
11
+
12
+
13
+ ```ps1
14
+
15
+ Using NameSpace System.Windows.Forms
16
+
17
+
18
+
19
+ Class MyForm : Form
20
+
21
+ {
22
+
23
+ [TextBox] $TxtBox1 = [TextBox]::new()
24
+
25
+ [TextBox] $TxtBox2 = [TextBox]::new()
26
+
27
+ [SplitContainer] $SplitContainer = [SplitContainer]::new()
28
+
29
+
30
+
31
+ MyForm()
32
+
33
+ {
34
+
35
+ $AnchorLeftTopRight = [AnchorStyles]::Left + [AnchorStyles]::Top + [AnchorStyles]::Right
36
+
37
+
38
+
39
+ $This.Controls.Add($This.SplitContainer)
40
+
41
+
42
+
43
+ $This.SplitContainer.Width = $This.ClientSize.Width
44
+
45
+ $This.SplitContainer.Anchor = $AnchorLeftTopRight
46
+
47
+
48
+
49
+ function AddTextBox
50
+
51
+ {
52
+
53
+ Param([Panel]$Panel, [TextBox]$TextBox, [ScriptBlock]$Script)
54
+
55
+ $Panel.Controls.Add($TextBox)
56
+
57
+ $TextBox.Width = $Panel.ClientSize.Width
58
+
59
+ $TextBox.Anchor = $AnchorLeftTopRight
60
+
61
+ $TextBox.Add_TextChanged($Script)
62
+
63
+ }
64
+
65
+
66
+
67
+ AddTextBox $This.SplitContainer.Panel1 $This.TxtBox1 {
68
+
69
+ $This.FindForm().TxtBox2.Text = $This.Text
70
+
71
+ }
72
+
73
+
74
+
75
+ AddTextBox $This.SplitContainer.Panel2 $This.TxtBox2 {
76
+
77
+ $This.FindForm().TxtBox1.Text = $This.Text
78
+
79
+ }
80
+
81
+ }
82
+
83
+ }
84
+
85
+
86
+
87
+ $Form = [MyForm]::new()
88
+
89
+
90
+
91
+ $Form.ShowDialog()
92
+
93
+ ```