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

質問編集履歴

3

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

2017/12/18 14:12

投稿

kaisen
kaisen

スコア28

title CHANGED
File without changes
body CHANGED
@@ -27,170 +27,180 @@
27
27
 
28
28
  ###該当のソースコード
29
29
  ```C#
30
- using System;
30
+ 1:using System;
31
- using System.Collections.Generic;
31
+ 2:using System.Collections.Generic;
32
+ 3:using System.ComponentModel;
33
+ 4:using System.Data;
32
- using System.Drawing;
34
+ 5:using System.Drawing;
35
+ 6:using System.Linq;
36
+ 7:using System.Text;
37
+ 8:using System.Threading.Tasks;
33
- using System.Windows.Forms;
38
+ 9:using System.Windows.Forms;
39
+ 10:using System.Collections;
40
+ 11:
41
+ 12:namespace WindowsFormsApp1
42
+ 13:{
43
+ 14: public partial class Form1 : Form
44
+ 15: {
45
+ 16: public Form1()
46
+ 17: {
47
+ 18: InitializeComponent();
48
+ 19: }
49
+ 20: // ------------------------------
50
+ 21: // クラスのメンバー変数として宣言
51
+ 22: // ------------------------------
52
+ 23: // ボタンのY座標
53
+ 24: int y =50;
54
+ 25: int x = 50;
55
+ 26:
56
+ 27: //動的リストの要素の添字として使うカウンタ
57
+ 28: int i = 0;
58
+ 29: int k = 0;
59
+ 30:
60
+ 31: // ボタンを格納しておく動的リスト
61
+ 32: List<Button> buttons = new List<Button>();
62
+ 33: // テキストボックスを格納しておく動的リスト
63
+ 34: List<TextBox> clist = new List<TextBox>();
64
+ 35:
65
+ 36:
66
+ 37: // ------------------------------
67
+ 38: // ボタン1が押された時の処理
68
+ 39: // ------------------------------
69
+ 40: private void button1_Click(object sender, System.EventArgs e)
70
+ 41: {
71
+ 42: // ボタンObjectを作成
72
+ 43: Button myButton = new Button();
73
+ 44:
74
+ 45: // ボタン位置を設定
75
+ 46: myButton.Location = new Point(0, y);
76
+ 47:
77
+ 48: // ボタンを追加
78
+ 49: this.Controls.Add(myButton);
79
+ 50:
80
+ 51: // ボタン同士が重ならないよう、位置をすこしずらす
81
+ 52: y = y + 24;
82
+ 53:
83
+ 54: // ボタンだけを集めた動的リストに今作ったボタンを追加
84
+ 55: buttons.Add(myButton);
85
+ 56:
86
+ 57: buttons[i].Click += new EventHandler(button1_Click);
87
+ 58:
88
+ 59: i++;
89
+ 60: }
90
+ 61:
91
+ 62: private void button2_Click(object sender, EventArgs e)
92
+ 63: {
93
+ 64:
94
+ 65: int y = 64;
95
+ 66: int x = 64;
96
+ 67: for (int a = 0; a < 5; a++)
97
+ 68: {
98
+ 69: TextBox tb = new TextBox();
99
+ 70: tb.Top = y;
100
+ 71: tb.Left = x;
101
+ 72: tb.Height = 24;
102
+ 73: tb.Width = 180;
103
+ 74: tb.Text = "hello";
104
+ 75: this.Controls.Add(tb);
105
+ 76:
106
+ 77: clist.Add(tb);
107
+ 78: y = y + 24 + 2;
108
+ 79: x = x + 50;
109
+ 80: }
110
+ 81: }
111
+ 82:
112
+ 83: private void button1_KeyPress(object sender, KeyPressEventArgs e)
113
+ 84: {
114
+ 85: //if (e.KeyChar == 49)//1が押されたとき
115
+ 86:
116
+ 87: if (e.KeyChar == (char)Keys.D)//Dキーが押されたとき
117
+ 88: {
118
+ 89: // ボタンObjectを作成
119
+ 90: Button myButton = new Button();
120
+ 91:
121
+ 92: // ボタン同士が重ならないよう、位置をすこしずらす
122
+ 93: y = y + 24;
123
+ 94:
124
+ 95: // ボタン位置を設定
125
+ 96: myButton.Location = new Point(x, y);
126
+ 97:
127
+ 98: // ボタンを追加
128
+ 99: this.Controls.Add(myButton);
129
+ 100:
130
+ 101: // ボタンだけを集めた動的リストに今作ったパネルを追加
131
+ 102: buttons.Add(myButton);
132
+ 103:
133
+ 104: buttons[i].Click += new EventHandler(button1_Click);
134
+ 105:
135
+ 106: i++;
136
+ 107: e.Handled = true;
137
+ 108: }
138
+ 109: if (e.KeyChar == (char)Keys.R)//Rキーが押されたとき
139
+ 110: {
140
+ 111: // ボタンObjectを作成
141
+ 112: Button myButton = new Button();
142
+ 113:
143
+ 114: //myButton.Text = Console.ReadLine();
144
+ 115:
145
+ 116: // ボタン同士が重ならないよう、位置をすこしずらす
146
+ 117: x = x + 24;
147
+ 118:
148
+ 119: // ボタン位置を設定
149
+ 120: myButton.Location = new Point(x, y);
150
+ 121:
151
+ 122: // ボタンを追加
152
+ 123: this.Controls.Add(myButton);
153
+ 124:
154
+ 125: // ボタンだけを集めた動的リストに今作ったパネルを追加
155
+ 126: buttons.Add(myButton);
156
+ 127:
157
+ 128: buttons[i].Click += new EventHandler(button1_Click);
158
+ 129:
159
+ 130: i++;
160
+ 131: e.Handled = true;
161
+ 132: }
162
+ 133: if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
163
+ 134: {
164
+ 135: TextBox tb = new TextBox();
165
+ 136: tb.Top = y;
166
+ 137: tb.Left = x;
167
+ 138: tb.Height = 24;
168
+ 139: tb.Width = 180;
169
+ 140: tb.Text = "hello";
170
+ 141: this.Controls.Add(tb);
171
+ 142:
172
+ 143: clist.Add(tb);
173
+ 144: clist[k].Click += new EventHandler(tb_Click);
174
+ 145: y = y + 24 + 2;
175
+ 146: x = x + 50;
176
+ 147: k++;
177
+ 148: e.Handled = true;
178
+ 149: }
179
+ 150: }
180
+ 151: private void tb_Click(object sender, KeyPressEventArgs e)
181
+ 152: {
182
+ 153:
183
+ 154: if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
184
+ 155: {
185
+ 156: TextBox tb = new TextBox();
186
+ 157: tb.Top = y;
187
+ 158: tb.Left = x;
188
+ 159: tb.Height = 24;
189
+ 160: tb.Width = 180;
190
+ 161: tb.Text = "hello";
191
+ 162: this.Controls.Add(tb);
192
+ 163: clist.Add(tb);
193
+ 164: clist[k].Click += new EventHandler(tb_Click);
194
+ 165:
195
+ 166: y = y + 24 + 2;
196
+ 167: x = x + 50;
197
+ 168: k++;
198
+ 169: e.Handled = true;
199
+ 170: }
200
+ 171: }
201
+ 172: }
202
+ 173:}
34
203
 
35
- namespace WindowsFormsApp1
36
- {
37
- public partial class Form1 : Form
38
- {
39
- public Form1()
40
- {
41
- InitializeComponent();
42
- }
43
- // ボタンのY座標
44
- int y =50;
45
- int x = 50;
46
-
47
- //動的リストの要素の添字として使うカウンタ
48
- int i = 0;
49
- int k = 0;
50
-
51
- // ボタンを格納しておく動的リスト
52
- List<Button> buttons = new List<Button>();
53
- // テキストボックスを格納しておく動的リスト
54
- List<TextBox> clist = new List<TextBox>();
55
-
56
-
57
- // ------------------------------
58
- // ボタン1が押された時の処理
59
- // ------------------------------
60
- private void button1_Click(object sender, System.EventArgs e)
61
- {
62
- // ボタンObjectを作成
63
- Button myButton = new Button();
64
-
65
- // ボタン位置を設定
66
- myButton.Location = new Point(0, y);
67
-
68
- // ボタンを追加
69
- this.Controls.Add(myButton);
70
-
71
- // ボタン同士が重ならないよう、位置をすこしずらす
72
- y = y + 24;
73
-
74
- // ボタンだけを集めた動的リストに今作ったボタンを追加
75
- buttons.Add(myButton);
76
-
77
- buttons[i].Click += new EventHandler(button1_Click);
78
-
79
- i++;
80
- }
81
-
82
- private void button2_Click(object sender, EventArgs e)
83
- {
84
-
85
- int y = 64;
86
- int x = 64;
87
- for (int a = 0; a < 5; a++)
88
- {
89
- TextBox tb = new TextBox();
90
- tb.Top = y;
91
- tb.Left = x;
92
- tb.Height = 24;
93
- tb.Width = 180;
94
- tb.Text = "hello";
95
- this.Controls.Add(tb);
96
-
97
- clist.Add(tb);
98
- y = y + 24 + 2;
99
- x = x + 50;
100
- }
101
- }
102
-
103
- private void button1_KeyPress(object sender, KeyPressEventArgs e)
104
- {
105
- //if (e.KeyChar == 49)//1が押されたとき
106
-
107
- if (e.KeyChar == (char)Keys.D)//Dキーが押されたとき
108
- {
109
- // ボタンObjectを作成
110
- Button myButton = new Button();
111
-
112
- // ボタン同士が重ならないよう、位置をすこしずらす
113
- y = y + 24;
114
-
115
- // ボタン位置を設定
116
- myButton.Location = new Point(x, y);
117
-
118
- // ボタンを追加
119
- this.Controls.Add(myButton);
120
-
121
- // ボタンだけを集めた動的リストに今作ったパネルを追加
122
- buttons.Add(myButton);
123
-
124
- buttons[i].Click += new EventHandler(button1_Click);
125
-
126
- i++;
127
- e.Handled = true;
128
- }
129
- if (e.KeyChar == (char)Keys.R)//Rキーが押されたとき
130
- {
131
- // ボタンObjectを作成
132
- Button myButton = new Button();
133
-
134
- //myButton.Text = Console.ReadLine();
135
-
136
- // ボタン同士が重ならないよう、位置をすこしずらす
137
- x = x + 24;
138
-
139
- // ボタン位置を設定
140
- myButton.Location = new Point(x, y);
141
-
142
- // ボタンを追加
143
- this.Controls.Add(myButton);
144
-
145
- // ボタンだけを集めた動的リストに今作ったパネルを追加
146
- buttons.Add(myButton);
147
-
148
- buttons[i].Click += new EventHandler(button1_Click);
149
-
150
- i++;
151
- e.Handled = true;
152
- }
153
- if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
154
- {
155
- TextBox tb = new TextBox();
156
- tb.Top = y;
157
- tb.Left = x;
158
- tb.Height = 24;
159
- tb.Width = 180;
160
- tb.Text = "hello";
161
- this.Controls.Add(tb);
162
-
163
- clist.Add(tb);
164
- clist[k].Click += new EventHandler(tb_Click);
165
- y = y + 24 + 2;
166
- x = x + 50;
167
- k++;
168
- e.Handled = true;
169
- }
170
- }
171
- private void tb_Click(object sender, KeyPressEventArgs e)
172
- {
173
-
174
- if (e.KeyChar == (char)Keys.T)//Tキーが押されたとき
175
- {
176
- TextBox tb = new TextBox();
177
- tb.Top = y;
178
- tb.Left = x;
179
- tb.Height = 24;
180
- tb.Width = 180;
181
- tb.Text = "hello";
182
- this.Controls.Add(tb);
183
- clist.Add(tb);
184
- clist[k].Click += new EventHandler(tb_Click);
185
-
186
- y = y + 24 + 2;
187
- x = x + 50;
188
- k++;
189
- e.Handled = true;
190
- }
191
- }
192
- }
193
- }
194
204
  ```
195
205
 
196
206
  ###試したこと

2

書式の改善

2017/12/18 14:12

投稿

kaisen
kaisen

スコア28

title CHANGED
@@ -1,1 +1,1 @@
1
- エラーCS0123 デリゲート '' に一致する '' のオーバーロードは~以下略
1
+ エラーCS0123 デリゲート 'EventHandler' に一致する 'tb_Click' のオーバーロードは~以下略
body CHANGED
@@ -1,30 +1,27 @@
1
1
  ###前提・実現したいこと
2
2
  こんばんは。
3
- C#でフォームアプリを作成中に
4
- タイトルのようなエラーが出ました。
3
+ C#でフォームアプリを作成中にタイトルのようなエラーが出ました。
5
4
 
6
5
  実現したいことは、
6
+
7
7
  「まず、
8
- Buttonを選択中に「T」キーを押すことで、
8
+ Buttonを選択中に「T」キーを押すことで、TextBox[A]を生成する。
9
- TextBox[A]を生成する。
10
9
 
11
- TextBox[A]でテキスト入力中に
10
+ TextBox[A]でテキスト入力中に特定のキーを入力することで、
12
- 特定のキーを入力することで、
13
11
  あらたなTextBox[B]を生成する。
14
12
 
15
- さらに、そのTextBox[B]においても、
13
+ さらに、そのTextBox[B]においても同じ特定のキーを入力することで
16
- 同じ特定のキーを入力することで、
17
14
  TextBox[C]を生成する、、、」
18
- というような動作をする
19
- フォームアプリを作ることです。
20
15
 
16
+ というような動作をするフォームアプリを作ることです。
17
+
21
18
  以下、
22
19
  エラーと、それが出たソースコードを記載します。
23
20
 
24
21
  ###発生している問題・エラーメッセージ
25
22
 
26
23
  ```
27
- エラー CS0123 デリゲート 'EventHandler' に一致する 'tb_Click' のオーバーロードはありません 144行目
24
+ エラー CS0123 デリゲート '' に一致する 'tb_Click' のオーバーロードはありません 144行目
28
25
  エラー CS0123 デリゲート 'EventHandler' に一致する 'tb_Click' のオーバーロードはありません 164行目
29
26
  ```
30
27
 

1

試したこと、に追記。

2017/12/18 14:07

投稿

kaisen
kaisen

スコア28

title CHANGED
File without changes
body CHANGED
@@ -202,6 +202,11 @@
202
202
  私が勝手にソースコードに試しに書いたものであって、
203
203
  デザイナーを使って自動的に生成されたコードではありません。
204
204
 
205
+ 現時点では、
206
+ エラー本文を検索したり、
207
+ デリゲートやらオーバーロードについて勉強しながら、
208
+ 解決策を見出そうとしています。
209
+
205
210
  ###補足情報(言語/FW/ツール等のバージョンなど)
206
211
  環境は、
207
212
  visualstudio2017 C# windowsフォームアプリケーション