teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

8

意図的に内容を抹消する行為にあたるため

2021/09/21 04:05

投稿

YeP95
YeP95

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- oaaaaaaaaaaaaaaaaaaa
1
+ 追加すパネル名を引数で設定する
body CHANGED
@@ -1,1 +1,82 @@
1
+ ```### 前提・実現したいこと
2
+ コンボボックスをパネルに追加する際、定数にパネル名を入れ、それを引数として受け取り、追加するパネルを判別したいのですがうまくいきません。(上手に説明できなくてすみません)
3
+ ### 発生している問題・エラーメッセージ
4
+ ```
5
+ エラーメッセージ
6
+ 'string' に 'Constrols' の定義が含まれておらず、型 'string' の最初の引数を受け付けるアクセス可能な拡張メソッド 'Constrols' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。
7
+ ### 該当のソースコード
8
+ ```c#
9
+ pname.Controls.Add(comboBox);
10
+ ``````ここに言語を入力
11
+ ```ここに言語を入力
12
+ ```
13
+ using System;
14
+ using System.Windows.Forms;
15
+ using System.Drawing;
16
+ class FormMain : Form
17
+ {
18
+ const string p1 = "panel1";
19
+ const string p2 = "panel2";
20
+ Panel panel1;
21
+ [STAThread]
22
+ public static void Main()
23
+ {
24
+ Application.EnableVisualStyles();
1
- ```aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
25
+ Application.SetCompatibleTextRenderingDefault(false);
26
+ Application.Run(new FormMain());
27
+ }
28
+ FormMain()
29
+ {
30
+ Text = "Button Click Sample";
31
+ ClientSize = new Size(600, 400);
32
+ Button btn1 = new Button();
33
+ btn1.Location = new Point(50, 50);
34
+ btn1.Text = "Create Panel";
35
+ btn1.Click += btn1_Click;
36
+ Controls.AddRange(new Control[] { btn1 });
37
+ this.Controls.Add(panel1);
38
+
39
+ }
40
+ public void CreateMyPanel( string pname )
41
+ {
42
+ panel1 = new Panel();
43
+ Panel panel2 = new Panel();
44
+ // Initialize the Panel control.
45
+ panel1.Location = new Point(56, 72);
46
+ panel1.Size = new Size(264, 152);
47
+ // Initialize the Panel control.
48
+ panel2.Location = new Point(356, 72);
49
+ panel2.Size = new Size(264, 152);
50
+ // Set the Borderstyle for the Panel to three-dimensional.
51
+ panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
52
+ panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
53
+ // Add the Panel control to the form.
54
+ this.Controls.Add(panel1);
55
+ this.Controls.Add(panel2);
56
+ ComboBox comboBox = new ComboBox();
57
+ comboBox.Items.Add("A");
58
+ comboBox.Items.Add("B");
59
+ comboBox.Items.Add("C");
60
+ comboBox.Items.Add("D");
61
+ comboBox.Items.Add("E");
62
+ pname.Controls.Add(comboBox);
63
+ }
64
+ void btn1_Click(object sender, System.EventArgs e)
65
+ {
66
+ CreateMyPanel(p1);
67
+ CreateMyPanel(p2);
68
+
69
+ }
70
+ }
71
+ ``````
72
+ ### 試したこと
73
+ ここに問題に対して試したことを記載してください。
74
+ ### 補足情報(FW/ツールのバージョンなど)
75
+ 訳あってif文は使えないため、↓の方法以外でお願いいたします・
76
+ ```ここに言語を入力
77
+ if (pname = p1 )
78
+ {panel1.Controls.Add(comboBox)}
79
+ else
80
+ {panel2.Controls.Add(comboBox)}
81
+ ```
82
+ ```

7

修正

2021/09/21 04:05

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 追加すパネル名を引数で設定する
1
+ oaaaaaaaaaaaaaaaaaaa
body CHANGED
@@ -1,109 +1,1 @@
1
- ```### 前提・実現したいこと
2
-
3
- コンボボックスをパネルに追加する際、定数にパネル名を入れ、それを引数として受け取り、追加するパネルを判別したいのですがうまくいきません。(上手に説明できなくてすみません)
4
-
5
- ### 発生している問題・エラーメッセージ
6
-
7
- ```
8
- エラーメッセージ
9
- 'string' に 'Constrols' の定義が含まれておらず、型 'string' の最初の引数を受け付けるアクセス可能な拡張メソッド 'Constrols' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。
10
-
11
- ### 該当のソースコード
12
-
13
- ```c#
14
- pname.Controls.Add(comboBox);
15
- ``````ここに言語を入力
16
- ```ここに言語を入力
17
- ```
18
- using System;
19
- using System.Windows.Forms;
20
- using System.Drawing;
21
-
22
- class FormMain : Form
23
- {
24
- const string p1 = "panel1";
25
- const string p2 = "panel2";
26
-
27
- Panel panel1;
28
-
29
-
30
- [STAThread]
31
- public static void Main()
32
- {
33
- Application.EnableVisualStyles();
34
- Application.SetCompatibleTextRenderingDefault(false);
1
+ ```aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
35
- Application.Run(new FormMain());
36
- }
37
-
38
- FormMain()
39
- {
40
-
41
- Text = "Button Click Sample";
42
- ClientSize = new Size(600, 400);
43
- Button btn1 = new Button();
44
- btn1.Location = new Point(50, 50);
45
- btn1.Text = "Create Panel";
46
- btn1.Click += btn1_Click;
47
- Controls.AddRange(new Control[] { btn1 });
48
-
49
- this.Controls.Add(panel1);
50
-
51
- }
52
-
53
- public void CreateMyPanel( string pname )
54
- {
55
- panel1 = new Panel();
56
- Panel panel2 = new Panel();
57
-
58
- // Initialize the Panel control.
59
- panel1.Location = new Point(56, 72);
60
- panel1.Size = new Size(264, 152);
61
-
62
- // Initialize the Panel control.
63
- panel2.Location = new Point(356, 72);
64
- panel2.Size = new Size(264, 152);
65
-
66
- // Set the Borderstyle for the Panel to three-dimensional.
67
- panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
68
- panel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
69
-
70
- // Add the Panel control to the form.
71
- this.Controls.Add(panel1);
72
- this.Controls.Add(panel2);
73
-
74
- ComboBox comboBox = new ComboBox();
75
- comboBox.Items.Add("A");
76
- comboBox.Items.Add("B");
77
- comboBox.Items.Add("C");
78
- comboBox.Items.Add("D");
79
- comboBox.Items.Add("E");
80
-
81
- pname.Controls.Add(comboBox);
82
-
83
- }
84
-
85
- void btn1_Click(object sender, System.EventArgs e)
86
- {
87
- CreateMyPanel(p1);
88
- CreateMyPanel(p2);
89
-
90
- }
91
- }
92
-
93
- ``````
94
-
95
- ### 試したこと
96
-
97
- ここに問題に対して試したことを記載してください。
98
-
99
- ### 補足情報(FW/ツールのバージョンなど)
100
-
101
- 訳あってif文は使えないため、↓の方法以外でお願いいたします・
102
-
103
- ```ここに言語を入力
104
- if (pname = p1 )
105
- {panel1.Controls.Add(comboBox)}
106
- else
107
- {panel2.Controls.Add(comboBox)}
108
- ```
109
- ```

6

修正

2021/09/19 17:18

投稿

YeP95
YeP95

スコア0

title CHANGED
File without changes
body CHANGED
@@ -85,6 +85,7 @@
85
85
  void btn1_Click(object sender, System.EventArgs e)
86
86
  {
87
87
  CreateMyPanel(p1);
88
+ CreateMyPanel(p2);
88
89
 
89
90
  }
90
91
  }

5

修正

2021/09/19 13:47

投稿

YeP95
YeP95

スコア0

title CHANGED
File without changes
body CHANGED
@@ -14,6 +14,7 @@
14
14
  pname.Controls.Add(comboBox);
15
15
  ``````ここに言語を入力
16
16
  ```ここに言語を入力
17
+ ```
17
18
  using System;
18
19
  using System.Windows.Forms;
19
20
  using System.Drawing;

4

修正

2021/09/19 13:21

投稿

YeP95
YeP95

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,3 @@
1
- `````````ここに言語を入力
2
- ここに言語を入力
3
- ```
4
- ここに言語を入力
5
- ```
6
- コード
7
1
  ```### 前提・実現したいこと
8
2
 
9
3
  コンボボックスをパネルに追加する際、定数にパネル名を入れ、それを引数として受け取り、追加するパネルを判別したいのですがうまくいきません。(上手に説明できなくてすみません)
@@ -15,10 +9,11 @@
15
9
  'string' に 'Constrols' の定義が含まれておらず、型 'string' の最初の引数を受け付けるアクセス可能な拡張メソッド 'Constrols' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。
16
10
 
17
11
  ### 該当のソースコード
12
+
13
+ ```c#
18
14
  pname.Controls.Add(comboBox);
19
- ```c#
20
- ソースコード
21
15
  ``````ここに言語を入力
16
+ ```ここに言語を入力
22
17
  using System;
23
18
  using System.Windows.Forms;
24
19
  using System.Drawing;
@@ -92,8 +87,9 @@
92
87
 
93
88
  }
94
89
  }
95
- ```
96
90
 
91
+ ``````
92
+
97
93
  ### 試したこと
98
94
 
99
95
  ここに問題に対して試したことを記載してください。
@@ -101,9 +97,11 @@
101
97
  ### 補足情報(FW/ツールのバージョンなど)
102
98
 
103
99
  訳あってif文は使えないため、↓の方法以外でお願いいたします・
100
+
104
101
  ```ここに言語を入力
105
102
  if (pname = p1 )
106
103
  {panel1.Controls.Add(comboBox)}
107
104
  else
108
105
  {panel2.Controls.Add(comboBox)}
106
+ ```
109
107
  ```

3

修正

2021/09/19 13:16

投稿

YeP95
YeP95

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,10 @@
1
+ `````````ここに言語を入力
2
+ ここに言語を入力
3
+ ```
4
+ ここに言語を入力
5
+ ```
6
+ コード
1
- ### 前提・実現したいこと
7
+ ```### 前提・実現したいこと
2
8
 
3
9
  コンボボックスをパネルに追加する際、定数にパネル名を入れ、それを引数として受け取り、追加するパネルを判別したいのですがうまくいきません。(上手に説明できなくてすみません)
4
10
 
@@ -12,7 +18,8 @@
12
18
  pname.Controls.Add(comboBox);
13
19
  ```c#
14
20
  ソースコード
21
+ ``````ここに言語を入力
15
- ```using System;
22
+ using System;
16
23
  using System.Windows.Forms;
17
24
  using System.Drawing;
18
25
 
@@ -85,6 +92,7 @@
85
92
 
86
93
  }
87
94
  }
95
+ ```
88
96
 
89
97
  ### 試したこと
90
98
 
@@ -93,7 +101,9 @@
93
101
  ### 補足情報(FW/ツールのバージョンなど)
94
102
 
95
103
  訳あってif文は使えないため、↓の方法以外でお願いいたします・
104
+ ```ここに言語を入力
96
105
  if (pname = p1 )
97
106
  {panel1.Controls.Add(comboBox)}
98
107
  else
99
- {panel2.Controls.Add(comboBox)}
108
+ {panel2.Controls.Add(comboBox)}
109
+ ```

2

補足の追加

2021/09/19 13:13

投稿

YeP95
YeP95

スコア0

title CHANGED
File without changes
body CHANGED
@@ -92,4 +92,8 @@
92
92
 
93
93
  ### 補足情報(FW/ツールのバージョンなど)
94
94
 
95
+ 訳あってif文は使えないため、↓の方法以外でお願いいたします・
95
- ここにより詳細な情報を記載してください。
96
+ if (pname = p1 )
97
+ {panel1.Controls.Add(comboBox)}
98
+ else
99
+ {panel2.Controls.Add(comboBox)}

1

タイトル変更

2021/09/19 13:00

投稿

YeP95
YeP95

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- 追加するパネル設定する設定する
1
+ 追加するパネル名を引数で設定する
body CHANGED
File without changes