質問編集履歴

3

ソースコードに行番号挿入

2017/12/18 14:12

投稿

kaisen
kaisen

スコア28

test CHANGED
File without changes
test CHANGED
@@ -56,333 +56,353 @@
56
56
 
57
57
  ```C#
58
58
 
59
- using System;
60
-
61
- using System.Collections.Generic;
62
-
63
- using System.Drawing;
64
-
65
- using System.Windows.Forms;
66
-
67
-
68
-
69
- namespace WindowsFormsApp1
70
-
71
- {
72
-
73
- public partial class Form1 : Form
74
-
75
- {
76
-
77
- public Form1()
78
-
79
- {
80
-
81
- InitializeComponent();
82
-
83
- }
84
-
85
- // ボタンのY座標
86
-
87
- int y =50;
88
-
89
- int x = 50;
90
-
91
-
92
-
93
- //動的リストの要素の添字として使うカウンタ
94
-
95
- int i = 0;
96
-
97
- int k = 0;
98
-
99
-
100
-
101
- // ボタンを格納しておく動的リスト
102
-
103
- List<Button> buttons = new List<Button>();
104
-
105
- // テキストボックスを格納しておく動的リスト
106
-
107
- List<TextBox> clist = new List<TextBox>();
108
-
109
-
110
-
111
-
112
-
113
- // ------------------------------
114
-
115
- // ボタン1が押された時の処理
116
-
117
- // ------------------------------
118
-
119
- private void button1_Click(object sender, System.EventArgs e)
120
-
121
- {
122
-
123
- // ボタンObject作成
124
-
125
- Button myButton = new Button();
126
-
127
-
128
-
129
- // ボタン位置を設定
130
-
131
- myButton.Location = new Point(0, y);
132
-
133
-
134
-
135
- // ボタンを追加
136
-
137
- this.Controls.Add(myButton);
138
-
139
-
140
-
141
- // ボタン同士が重ならないよう、位置すこしずらす
142
-
143
- y = y + 24;
144
-
145
-
146
-
147
- // ボタンだけ集めた動的リストに今作ったボタンを追加
148
-
149
- buttons.Add(myButton);
150
-
151
-
152
-
153
- buttons[i].Click += new EventHandler(button1_Click);
154
-
155
-
156
-
157
- i++;
158
-
159
- }
160
-
161
-
162
-
163
- private void button2_Click(object sender, EventArgs e)
164
-
165
- {
166
-
167
-
168
-
169
- int y = 64;
170
-
171
- int x = 64;
172
-
173
- for (int a = 0; a < 5; a++)
174
-
175
- {
176
-
177
- TextBox tb = new TextBox();
178
-
179
- tb.Top = y;
180
-
181
- tb.Left = x;
182
-
183
- tb.Height = 24;
184
-
185
- tb.Width = 180;
186
-
187
- tb.Text = "hello";
188
-
189
- this.Controls.Add(tb);
190
-
191
-
192
-
193
- clist.Add(tb);
194
-
195
- y = y + 24 + 2;
196
-
197
- x = x + 50;
198
-
199
- }
200
-
201
- }
202
-
203
-
204
-
205
- private void button1_KeyPress(object sender, KeyPressEventArgs e)
206
-
207
- {
208
-
209
- //if (e.KeyChar == 49)//1が押されたとき
210
-
211
-
212
-
213
- if (e.KeyChar == (char)Keys.D)//Dキーが押されたとき
214
-
215
- {
216
-
217
- // ボタンObjectを作成
218
-
219
- Button myButton = new Button();
220
-
221
-
222
-
223
- // ボタン同士が重ならないよう、位置をすこしずらす
224
-
225
- y = y + 24;
226
-
227
-
228
-
229
- // ボタン位置を設定
230
-
231
- myButton.Location = new Point(x, y);
232
-
233
-
234
-
235
- // ボタンを追加
236
-
237
- this.Controls.Add(myButton);
238
-
239
-
240
-
241
- // ボタンだけ集めた動的リストに今作ったパネルを追加
242
-
243
- buttons.Add(myButton);
244
-
245
-
246
-
247
- buttons[i].Click += new EventHandler(button1_Click);
248
-
249
-
250
-
251
- i++;
252
-
253
- e.Handled = true;
254
-
255
- }
256
-
257
- if (e.KeyChar == (char)Keys.R)//Rキーが押されたとき
258
-
259
- {
260
-
261
- // ボタンObjectを作成
262
-
263
- Button myButton = new Button();
264
-
265
-
266
-
267
- //myButton.Text = Console.ReadLine();
268
-
269
-
270
-
271
- // ボタン同士が重ならないよう、位置をすこしずらす
272
-
273
- x = x + 24;
274
-
275
-
276
-
277
- // ボタン位置を設定
278
-
279
- myButton.Location = new Point(x, y);
280
-
281
-
282
-
283
- // ボタンを追加
284
-
285
- this.Controls.Add(myButton);
286
-
287
-
288
-
289
- // ボタンだけ集めた動的リストに今作ったパネルを追加
290
-
291
- buttons.Add(myButton);
292
-
293
-
294
-
295
- buttons[i].Click += new EventHandler(button1_Click);
296
-
297
-
298
-
299
- i++;
300
-
301
- e.Handled = true;
302
-
303
- }
304
-
305
- if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
306
-
307
- {
308
-
309
- TextBox tb = new TextBox();
310
-
311
- tb.Top = y;
312
-
313
- tb.Left = x;
314
-
315
- tb.Height = 24;
316
-
317
- tb.Width = 180;
318
-
319
- tb.Text = "hello";
320
-
321
- this.Controls.Add(tb);
322
-
323
-
324
-
325
- clist.Add(tb);
326
-
327
- clist[k].Click += new EventHandler(tb_Click);
328
-
329
- y = y + 24 + 2;
330
-
331
- x = x + 50;
332
-
333
- k++;
334
-
335
- e.Handled = true;
336
-
337
- }
338
-
339
- }
340
-
341
- private void tb_Click(object sender, KeyPressEventArgs e)
342
-
343
- {
344
-
345
-
346
-
347
- if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
348
-
349
- {
350
-
351
- TextBox tb = new TextBox();
352
-
353
- tb.Top = y;
354
-
355
- tb.Left = x;
356
-
357
- tb.Height = 24;
358
-
359
- tb.Width = 180;
360
-
361
- tb.Text = "hello";
362
-
363
- this.Controls.Add(tb);
364
-
365
- clist.Add(tb);
366
-
367
- clist[k].Click += new EventHandler(tb_Click);
368
-
369
-
370
-
371
- y = y + 24 + 2;
372
-
373
- x = x + 50;
374
-
375
- k++;
376
-
377
- e.Handled = true;
378
-
379
- }
380
-
381
- }
382
-
383
- }
384
-
385
- }
59
+ 1:using System;
60
+
61
+ 2:using System.Collections.Generic;
62
+
63
+ 3:using System.ComponentModel;
64
+
65
+ 4:using System.Data;
66
+
67
+ 5:using System.Drawing;
68
+
69
+ 6:using System.Linq;
70
+
71
+ 7:using System.Text;
72
+
73
+ 8:using System.Threading.Tasks;
74
+
75
+ 9:using System.Windows.Forms;
76
+
77
+ 10:using System.Collections;
78
+
79
+ 11:
80
+
81
+ 12:namespace WindowsFormsApp1
82
+
83
+ 13:{
84
+
85
+ 14: public partial class Form1 : Form
86
+
87
+ 15: {
88
+
89
+ 16: public Form1()
90
+
91
+ 17: {
92
+
93
+ 18: InitializeComponent();
94
+
95
+ 19: }
96
+
97
+ 20: // ------------------------------
98
+
99
+ 21: // クラスのメンバー変数として宣言
100
+
101
+ 22: // ------------------------------
102
+
103
+ 23: // ボタンのY座標
104
+
105
+ 24: int y =50;
106
+
107
+ 25: int x = 50;
108
+
109
+ 26:
110
+
111
+ 27: //動的リストの要素の添字として使うカウンタ
112
+
113
+ 28: int i = 0;
114
+
115
+ 29: int k = 0;
116
+
117
+ 30:
118
+
119
+ 31: // ボタンを格納しておく動的リスト
120
+
121
+ 32: List<Button> buttons = new List<Button>();
122
+
123
+ 33: // テキストックス格納しておく動的リスト
124
+
125
+ 34: List<TextBox> clist = new List<TextBox>();
126
+
127
+ 35:
128
+
129
+ 36:
130
+
131
+ 37: // ------------------------------
132
+
133
+ 38: // ボタン1が押された時の処理
134
+
135
+ 39: // ------------------------------
136
+
137
+ 40: private void button1_Click(object sender, System.EventArgs e)
138
+
139
+ 41: {
140
+
141
+ 42: // ボタンObject作成
142
+
143
+ 43: Button myButton = new Button();
144
+
145
+ 44:
146
+
147
+ 45: // ボタン位置設定
148
+
149
+ 46: myButton.Location = new Point(0, y);
150
+
151
+ 47:
152
+
153
+ 48: // ボタンを追加
154
+
155
+ 49: this.Controls.Add(myButton);
156
+
157
+ 50:
158
+
159
+ 51: // ボタン同士が重ならないよう、位置をすこしずらす
160
+
161
+ 52: y = y + 24;
162
+
163
+ 53:
164
+
165
+ 54: // ボタンだけを集めた動的リストに今作ったボタンを追加
166
+
167
+ 55: buttons.Add(myButton);
168
+
169
+ 56:
170
+
171
+ 57: buttons[i].Click += new EventHandler(button1_Click);
172
+
173
+ 58:
174
+
175
+ 59: i++;
176
+
177
+ 60: }
178
+
179
+ 61:
180
+
181
+ 62: private void button2_Click(object sender, EventArgs e)
182
+
183
+ 63: {
184
+
185
+ 64:
186
+
187
+ 65: int y = 64;
188
+
189
+ 66: int x = 64;
190
+
191
+ 67: for (int a = 0; a < 5; a++)
192
+
193
+ 68: {
194
+
195
+ 69: TextBox tb = new TextBox();
196
+
197
+ 70: tb.Top = y;
198
+
199
+ 71: tb.Left = x;
200
+
201
+ 72: tb.Height = 24;
202
+
203
+ 73: tb.Width = 180;
204
+
205
+ 74: tb.Text = "hello";
206
+
207
+ 75: this.Controls.Add(tb);
208
+
209
+ 76:
210
+
211
+ 77: clist.Add(tb);
212
+
213
+ 78: y = y + 24 + 2;
214
+
215
+ 79: x = x + 50;
216
+
217
+ 80: }
218
+
219
+ 81: }
220
+
221
+ 82:
222
+
223
+ 83: private void button1_KeyPress(object sender, KeyPressEventArgs e)
224
+
225
+ 84: {
226
+
227
+ 85: //if (e.KeyChar == 49)//1が押されたとき
228
+
229
+ 86:
230
+
231
+ 87: if (e.KeyChar == (char)Keys.D)//Dキーが押されたとき
232
+
233
+ 88: {
234
+
235
+ 89: // ボタンObject作成
236
+
237
+ 90: Button myButton = new Button();
238
+
239
+ 91:
240
+
241
+ 92: // ボタン同士が重ならないよう、位置すこしずらす
242
+
243
+ 93: y = y + 24;
244
+
245
+ 94:
246
+
247
+ 95: // ボタン位置を設定
248
+
249
+ 96: myButton.Location = new Point(x, y);
250
+
251
+ 97:
252
+
253
+ 98: // ボタンを追加
254
+
255
+ 99: this.Controls.Add(myButton);
256
+
257
+ 100:
258
+
259
+ 101: // ボタンだけを集めた動的リストに今作ったパネルを追加
260
+
261
+ 102: buttons.Add(myButton);
262
+
263
+ 103:
264
+
265
+ 104: buttons[i].Click += new EventHandler(button1_Click);
266
+
267
+ 105:
268
+
269
+ 106: i++;
270
+
271
+ 107: e.Handled = true;
272
+
273
+ 108: }
274
+
275
+ 109: if (e.KeyChar == (char)Keys.R)//Rキーが押されたとき
276
+
277
+ 110: {
278
+
279
+ 111: // ボタンObjectを作成
280
+
281
+ 112: Button myButton = new Button();
282
+
283
+ 113:
284
+
285
+ 114: //myButton.Text = Console.ReadLine();
286
+
287
+ 115:
288
+
289
+ 116: // ボタン同士が重ならないよう、位置すこしずらす
290
+
291
+ 117: x = x + 24;
292
+
293
+ 118:
294
+
295
+ 119: // ボタン位置を設定
296
+
297
+ 120: myButton.Location = new Point(x, y);
298
+
299
+ 121:
300
+
301
+ 122: // ボタンを追加
302
+
303
+ 123: this.Controls.Add(myButton);
304
+
305
+ 124:
306
+
307
+ 125: // ボタンだけを集めた動的リストに今作ったパネルを追加
308
+
309
+ 126: buttons.Add(myButton);
310
+
311
+ 127:
312
+
313
+ 128: buttons[i].Click += new EventHandler(button1_Click);
314
+
315
+ 129:
316
+
317
+ 130: i++;
318
+
319
+ 131: e.Handled = true;
320
+
321
+ 132: }
322
+
323
+ 133: if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
324
+
325
+ 134: {
326
+
327
+ 135: TextBox tb = new TextBox();
328
+
329
+ 136: tb.Top = y;
330
+
331
+ 137: tb.Left = x;
332
+
333
+ 138: tb.Height = 24;
334
+
335
+ 139: tb.Width = 180;
336
+
337
+ 140: tb.Text = "hello";
338
+
339
+ 141: this.Controls.Add(tb);
340
+
341
+ 142:
342
+
343
+ 143: clist.Add(tb);
344
+
345
+ 144: clist[k].Click += new EventHandler(tb_Click);
346
+
347
+ 145: y = y + 24 + 2;
348
+
349
+ 146: x = x + 50;
350
+
351
+ 147: k++;
352
+
353
+ 148: e.Handled = true;
354
+
355
+ 149: }
356
+
357
+ 150: }
358
+
359
+ 151: private void tb_Click(object sender, KeyPressEventArgs e)
360
+
361
+ 152: {
362
+
363
+ 153:
364
+
365
+ 154: if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
366
+
367
+ 155: {
368
+
369
+ 156: TextBox tb = new TextBox();
370
+
371
+ 157: tb.Top = y;
372
+
373
+ 158: tb.Left = x;
374
+
375
+ 159: tb.Height = 24;
376
+
377
+ 160: tb.Width = 180;
378
+
379
+ 161: tb.Text = "hello";
380
+
381
+ 162: this.Controls.Add(tb);
382
+
383
+ 163: clist.Add(tb);
384
+
385
+ 164: clist[k].Click += new EventHandler(tb_Click);
386
+
387
+ 165:
388
+
389
+ 166: y = y + 24 + 2;
390
+
391
+ 167: x = x + 50;
392
+
393
+ 168: k++;
394
+
395
+ 169: e.Handled = true;
396
+
397
+ 170: }
398
+
399
+ 171: }
400
+
401
+ 172: }
402
+
403
+ 173:}
404
+
405
+
386
406
 
387
407
  ```
388
408
 

2

書式の改善

2017/12/18 14:12

投稿

kaisen
kaisen

スコア28

test CHANGED
@@ -1 +1 @@
1
- エラーCS0123 デリゲート '' に一致する '' のオーバーロードは~以下略
1
+ エラーCS0123 デリゲート 'EventHandler' に一致する 'tb_Click' のオーバーロードは~以下略
test CHANGED
@@ -2,39 +2,33 @@
2
2
 
3
3
  こんばんは。
4
4
 
5
- C#でフォームアプリを作成中に
6
-
7
- タイトルのようなエラーが出ました。
5
+ C#でフォームアプリを作成中にタイトルのようなエラーが出ました。
8
6
 
9
7
 
10
8
 
11
9
  実現したいことは、
12
10
 
11
+
12
+
13
13
  「まず、
14
14
 
15
- Buttonを選択中に「T」キーを押すことで、
15
+ Buttonを選択中に「T」キーを押すことで、TextBox[A]を生成する。
16
-
17
- TextBox[A]を生成する。
16
+
18
-
19
-
20
-
17
+
18
+
21
- TextBox[A]でテキスト入力中に
19
+ TextBox[A]でテキスト入力中に特定のキーを入力することで、
22
-
23
- 特定のキーを入力することで、
24
20
 
25
21
  あらたなTextBox[B]を生成する。
26
22
 
27
23
 
28
24
 
29
- さらに、そのTextBox[B]においても、
25
+ さらに、そのTextBox[B]においても同じ特定のキーを入力することで
30
-
31
- 同じ特定のキーを入力することで、
32
26
 
33
27
  TextBox[C]を生成する、、、」
34
28
 
35
- というような動作をする
29
+
36
-
30
+
37
- フォームアプリを作ることです。
31
+ というような動作をするフォームアプリを作ることです。
38
32
 
39
33
 
40
34
 
@@ -50,7 +44,7 @@
50
44
 
51
45
  ```
52
46
 
53
- エラー CS0123 デリゲート 'EventHandler' に一致する 'tb_Click' のオーバーロードはありません 144行目
47
+ エラー CS0123 デリゲート '' に一致する 'tb_Click' のオーバーロードはありません 144行目
54
48
 
55
49
  エラー CS0123 デリゲート 'EventHandler' に一致する 'tb_Click' のオーバーロードはありません 164行目
56
50
 

1

試したこと、に追記。

2017/12/18 14:07

投稿

kaisen
kaisen

スコア28

test CHANGED
File without changes
test CHANGED
@@ -406,6 +406,16 @@
406
406
 
407
407
 
408
408
 
409
+ 現時点では、
410
+
411
+ エラー本文を検索したり、
412
+
413
+ デリゲートやらオーバーロードについて勉強しながら、
414
+
415
+ 解決策を見出そうとしています。
416
+
417
+
418
+
409
419
  ###補足情報(言語/FW/ツール等のバージョンなど)
410
420
 
411
421
  環境は、