回答編集履歴

2

追記

2020/05/07 09:51

投稿

YAmaGNZ
YAmaGNZ

スコア10242

test CHANGED
@@ -15,3 +15,61 @@
15
15
  ```
16
16
 
17
17
  とするのではダメなのでしょうか?
18
+
19
+
20
+
21
+ ### 追記
22
+
23
+ デザイナで配置したら
24
+
25
+ ![イメージ説明](17d935a2be6b4c9849a9ce4d68c0a912.png)
26
+
27
+ このような感じだと思います。
28
+
29
+ そして、下記のように配置した名前でアクセスできるはずです。
30
+
31
+
32
+
33
+ フォーム側
34
+
35
+ ```C#
36
+
37
+ private void button1_Click(object sender, EventArgs e)
38
+
39
+ {
40
+
41
+ userControl11.testc();
42
+
43
+ }
44
+
45
+ ```
46
+
47
+ UserControl1側
48
+
49
+ ```C#
50
+
51
+ public partial class UserControl1 : UserControl
52
+
53
+ {
54
+
55
+ public UserControl1()
56
+
57
+ {
58
+
59
+ InitializeComponent();
60
+
61
+ }
62
+
63
+
64
+
65
+ public void testc()
66
+
67
+ {
68
+
69
+ textBox1.Text = "cde";
70
+
71
+ }
72
+
73
+ }
74
+
75
+ ```

1

編集

2020/05/07 09:51

投稿

YAmaGNZ
YAmaGNZ

スコア10242

test CHANGED
@@ -4,11 +4,13 @@
4
4
 
5
5
  なぜstaticメソッドでインスタンスを管理しようとしているのか分かりませんが
6
6
 
7
+ デザイナでUserControl1を配置しているのではないですか?
8
+
7
- ただ
9
+ そのインスタンス(仮にusercontrol1とします)で
8
10
 
9
11
  ```C#
10
12
 
11
- UserControl1.testc();
13
+ usercontrol1.testc();
12
14
 
13
15
  ```
14
16