質問編集履歴
3
質問の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
コード
|
2
2
|
|
3
|
-
```
|
3
|
+
```C#
|
4
4
|
|
5
5
|
namespace RubikCube
|
6
6
|
|
@@ -320,6 +320,58 @@
|
|
320
320
|
|
321
321
|
```
|
322
322
|
|
323
|
+
InitializeComponentメソッド内(コントロールは省略しています)
|
324
|
+
|
325
|
+
```C#
|
326
|
+
|
327
|
+
// RubikCubeForm
|
328
|
+
|
329
|
+
//
|
330
|
+
|
331
|
+
this.AutoScaleDimensions = new System.Drawing.SizeF(27F, 48F);
|
332
|
+
|
333
|
+
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
334
|
+
|
335
|
+
this.ClientSize = new System.Drawing.Size(778, 644);
|
336
|
+
|
337
|
+
this.Controls.Add(this.label2);
|
338
|
+
|
339
|
+
this.Controls.Add(this.label1);
|
340
|
+
|
341
|
+
this.Controls.Add(this.backToSetupbutton);
|
342
|
+
|
343
|
+
this.Controls.Add(this.resetbutton);
|
344
|
+
|
345
|
+
this.Font = new System.Drawing.Font("MS UI Gothic", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
|
346
|
+
|
347
|
+
this.Margin = new System.Windows.Forms.Padding(9, 8, 9, 8);
|
348
|
+
|
349
|
+
this.Name = "RubikCubeForm";
|
350
|
+
|
351
|
+
this.StartPosition =
|
352
|
+
|
353
|
+
System.Windows.Forms.FormStartPosition.CenterScreen;
|
354
|
+
|
355
|
+
this.Text = "RubikCubeForm";
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
// this.Activated += new System.EventHandler(this.RubikCubeForm_Load);
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
this.Load += new System.EventHandler(this.RubikCubeForm_Load);
|
364
|
+
|
365
|
+
this.ResumeLayout(false);
|
366
|
+
|
367
|
+
this.PerformLayout();
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
```
|
374
|
+
|
323
375
|
```### 前提・実現したいこと
|
324
376
|
|
325
377
|
今年のLINEのインターンシップのコーディングテストであったような二次元ルービックキューブを作ろうとしており、動作としては、各列・行にあるボタンをクリックするとクリックした列もしくは行が縦・横に一つずつずれるというものです。しかし上に配置したボタン(Text="↓"のボタンです)をクリックしても列がずれません。ずれるはずの列の各Label(ここではdigitLabel)のTextプロパティの文字はしっかりとずれているのですが画面上に反映されません。
|
@@ -329,3 +381,9 @@
|
|
329
381
|
|
330
382
|
|
331
383
|
お詳しいかたお助けください。
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
追記
|
388
|
+
|
389
|
+
ここに出していないコードに問題がありました。というのも、子フォーム(ここでいうsetupForm)で再びサイズ変更をできるようにしようとしており、子フォームで設定したサイズをもとに親フォームの画面も更新させる、ということでActiveになったら発生するActivatedイベントにもRubikCubeForm_Loadメソッドを追加していました。そのActivatedにも追加している文を削除したらうまくいきました。しかし、そこで新たな質問が生まれてしまいました。。なぜ、Activatedに追加するとうまくいかなかったのでしょうか。Activatedの解釈が間違っていますか。質問に追加します。
|
2
コードを囲いました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,329 +1,325 @@
|
|
1
|
-
```C#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
1
|
コード
|
6
2
|
|
3
|
+
``````C#
|
4
|
+
|
5
|
+
namespace RubikCube
|
6
|
+
|
7
|
+
{
|
8
|
+
|
9
|
+
public partial class RubikCubeForm : Form
|
10
|
+
|
11
|
+
{
|
12
|
+
|
13
|
+
private SetupForm _setupForm;
|
14
|
+
|
15
|
+
private Label[] digitLabel;
|
16
|
+
|
17
|
+
private Button[] moveVerticalUpButton;
|
18
|
+
|
19
|
+
private Button[] moveVerticalDownButton;
|
20
|
+
|
21
|
+
private Button[] moveHorizonLeftButton;
|
22
|
+
|
23
|
+
private Button[] moveHorizonRightButton;
|
24
|
+
|
25
|
+
private bool IsClickButton = false;
|
26
|
+
|
27
|
+
private int _rubiksize;
|
28
|
+
|
29
|
+
private int _digitLabelSize;
|
30
|
+
|
31
|
+
public RubikCubeForm()
|
32
|
+
|
33
|
+
{
|
34
|
+
|
35
|
+
_setupForm = new SetupForm();
|
36
|
+
|
37
|
+
_setupForm.ShowDialog();
|
38
|
+
|
39
|
+
InitializeComponent();
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
private void RubikCubeForm_Load(object sender, EventArgs e)
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
if (!IsClickButton)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
_rubiksize = int.Parse(_setupForm._rubikSize);
|
54
|
+
|
55
|
+
_tempDigitLabel = new string[_rubiksize];
|
56
|
+
|
57
|
+
CreateRubikCube();
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
private void backToSetupbutton_Click(object sender, EventArgs e)
|
68
|
+
|
69
|
+
{
|
70
|
+
|
71
|
+
IsClickButton=false;
|
72
|
+
|
73
|
+
_setupForm.ShowDialog();
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
private void CreateRubikCube()
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
int tempCreateRubikCube = _rubiksize / 2;
|
84
|
+
|
85
|
+
_digitLabelSize = 50;
|
86
|
+
|
87
|
+
var startDigitLabelX = Width / 2 - (tempCreateRubikCube * _digitLabelSize);
|
88
|
+
|
89
|
+
var startDigitLabelY = Height / 2 - (tempCreateRubikCube * _digitLabelSize) - 50;
|
90
|
+
|
91
|
+
digitLabel = new Label[_rubiksize * _rubiksize];
|
92
|
+
|
93
|
+
moveVerticalUpButton = new Button[_rubiksize];
|
94
|
+
|
95
|
+
moveVerticalDownButton = new Button[_rubiksize];
|
96
|
+
|
97
|
+
moveHorizonLeftButton = new Button[_rubiksize];
|
98
|
+
|
99
|
+
moveHorizonRightButton = new Button[_rubiksize];
|
100
|
+
|
101
|
+
SuspendLayout();
|
102
|
+
|
103
|
+
for (var i = 0; i < _rubiksize; i++)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
for (var j = 0; j < _rubiksize; j++)
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
//数字配置
|
114
|
+
|
115
|
+
digitLabel[j + _rubiksize * i] = new Label();
|
116
|
+
|
117
|
+
digitLabel[j + _rubiksize * i].Text = (1 + j + _rubiksize * i).ToString();
|
118
|
+
|
119
|
+
digitLabel[j + _rubiksize * i].Location = new Point(startDigitLabelX + j * _digitLabelSize,
|
120
|
+
|
121
|
+
startDigitLabelY + i * _digitLabelSize);
|
122
|
+
|
123
|
+
digitLabel[j + _rubiksize * i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
124
|
+
|
125
|
+
digitLabel[j + _rubiksize * i].TextAlign = ContentAlignment.MiddleCenter;
|
126
|
+
|
127
|
+
digitLabel[j + _rubiksize * i].Font = new Font("MS UI Gothic", 18, FontStyle.Bold);
|
128
|
+
|
129
|
+
Controls.Add(digitLabel[j + _rubiksize * i]);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
//ボタン配置
|
136
|
+
|
137
|
+
//上
|
138
|
+
|
139
|
+
moveVerticalUpButton[i] = new Button();
|
140
|
+
|
141
|
+
moveVerticalUpButton[i].Text = "↓";
|
142
|
+
|
143
|
+
moveVerticalUpButton[i].Name = i.ToString();
|
144
|
+
|
145
|
+
moveVerticalUpButton[i].Location =
|
146
|
+
|
147
|
+
new Point(startDigitLabelX + i * _digitLabelSize,
|
148
|
+
|
149
|
+
startDigitLabelY - _digitLabelSize);
|
150
|
+
|
151
|
+
moveVerticalUpButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
152
|
+
|
153
|
+
moveVerticalUpButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
154
|
+
|
155
|
+
moveVerticalUpButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
156
|
+
|
157
|
+
moveVerticalUpButton[i].Click += new EventHandler(MoveUp_Click);
|
158
|
+
|
159
|
+
//下
|
160
|
+
|
161
|
+
moveVerticalDownButton[i] = new Button();
|
162
|
+
|
163
|
+
moveVerticalDownButton[i].Text = "↑";
|
164
|
+
|
165
|
+
moveVerticalDownButton[i].Name = i.ToString();
|
166
|
+
|
167
|
+
moveVerticalDownButton[i].Location =
|
168
|
+
|
169
|
+
new Point(startDigitLabelX + i * _digitLabelSize,
|
170
|
+
|
171
|
+
startDigitLabelY + (_rubiksize * _digitLabelSize));
|
172
|
+
|
173
|
+
moveVerticalDownButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
174
|
+
|
175
|
+
moveVerticalDownButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
176
|
+
|
177
|
+
moveVerticalDownButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
178
|
+
|
179
|
+
moveVerticalDownButton[i].Click += new EventHandler(MoveDown_Click);
|
180
|
+
|
181
|
+
//左
|
182
|
+
|
183
|
+
moveHorizonLeftButton[i] = new Button();
|
184
|
+
|
185
|
+
moveHorizonLeftButton[i].Text = "→";
|
186
|
+
|
187
|
+
moveHorizonLeftButton[i].Name = i.ToString();
|
188
|
+
|
189
|
+
moveHorizonLeftButton[i].Location =
|
190
|
+
|
191
|
+
new Point(startDigitLabelX - _digitLabelSize,
|
192
|
+
|
193
|
+
startDigitLabelY + i * _digitLabelSize);
|
194
|
+
|
195
|
+
moveHorizonLeftButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
196
|
+
|
197
|
+
moveHorizonLeftButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
198
|
+
|
199
|
+
moveHorizonLeftButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
200
|
+
|
201
|
+
moveHorizonLeftButton[i].Click += new EventHandler(MoveLeft_Click);
|
202
|
+
|
203
|
+
//右
|
204
|
+
|
205
|
+
moveHorizonRightButton[i] = new Button();
|
206
|
+
|
207
|
+
moveHorizonRightButton[i].Text = "←";
|
208
|
+
|
209
|
+
moveHorizonRightButton[i].Name = i.ToString();
|
210
|
+
|
211
|
+
moveHorizonRightButton[i].Location =
|
212
|
+
|
213
|
+
new Point(startDigitLabelX + (_rubiksize * _digitLabelSize),
|
214
|
+
|
215
|
+
startDigitLabelY + i * _digitLabelSize);
|
216
|
+
|
217
|
+
moveHorizonRightButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
218
|
+
|
219
|
+
moveHorizonRightButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
220
|
+
|
221
|
+
moveHorizonRightButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
222
|
+
|
223
|
+
moveHorizonRightButton[i].Click += new EventHandler(MoveRight_Click);
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
Controls.AddRange(moveVerticalUpButton);
|
228
|
+
|
229
|
+
Controls.AddRange(moveVerticalDownButton);
|
230
|
+
|
231
|
+
Controls.AddRange(moveHorizonLeftButton);
|
232
|
+
|
233
|
+
Controls.AddRange(moveHorizonRightButton);
|
234
|
+
|
235
|
+
ResumeLayout();
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
private int _clickButtonNum;
|
242
|
+
|
243
|
+
private string[] _tempDigitLabel;
|
244
|
+
|
245
|
+
private void MoveUp_Click(object sender, EventArgs e)
|
246
|
+
|
247
|
+
{
|
248
|
+
|
249
|
+
IsClickButton = true;
|
250
|
+
|
251
|
+
_clickButtonNum = int.Parse(((Button)sender).Name);
|
252
|
+
|
253
|
+
label2.Text = ((Button)sender).Name;
|
254
|
+
|
255
|
+
for (var i = 0; i < _rubiksize; i++)
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
_tempDigitLabel[i] = digitLabel[_clickButtonNum + i * _rubiksize].Text;
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
for (var i = 0; i < _rubiksize; i++)
|
264
|
+
|
265
|
+
{
|
266
|
+
|
267
|
+
if (i == 0)
|
268
|
+
|
269
|
+
{
|
270
|
+
|
271
|
+
digitLabel[_clickButtonNum + i * _rubiksize].Text = _tempDigitLabel[_rubiksize - 1];
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
else
|
276
|
+
|
277
|
+
digitLabel[_clickButtonNum + i * _rubiksize].Text = _tempDigitLabel[i - 1];
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
private void MoveDown_Click(object sender, EventArgs e)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
private void MoveLeft_Click(object sender, EventArgs e)
|
298
|
+
|
299
|
+
{
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
private void MoveRight_Click(object sender, EventArgs e)
|
308
|
+
|
309
|
+
{
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
}
|
320
|
+
|
7
321
|
```
|
8
322
|
|
9
|
-
namespace RubikCube
|
10
|
-
|
11
|
-
{
|
12
|
-
|
13
|
-
public partial class RubikCubeForm : Form
|
14
|
-
|
15
|
-
{
|
16
|
-
|
17
|
-
private SetupForm _setupForm;
|
18
|
-
|
19
|
-
private Label[] digitLabel;
|
20
|
-
|
21
|
-
private Button[] moveVerticalUpButton;
|
22
|
-
|
23
|
-
private Button[] moveVerticalDownButton;
|
24
|
-
|
25
|
-
private Button[] moveHorizonLeftButton;
|
26
|
-
|
27
|
-
private Button[] moveHorizonRightButton;
|
28
|
-
|
29
|
-
private bool IsClickButton = false;
|
30
|
-
|
31
|
-
private int _rubiksize;
|
32
|
-
|
33
|
-
private int _digitLabelSize;
|
34
|
-
|
35
|
-
public RubikCubeForm()
|
36
|
-
|
37
|
-
{
|
38
|
-
|
39
|
-
_setupForm = new SetupForm();
|
40
|
-
|
41
|
-
_setupForm.ShowDialog();
|
42
|
-
|
43
|
-
InitializeComponent();
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
private void RubikCubeForm_Load(object sender, EventArgs e)
|
50
|
-
|
51
|
-
{
|
52
|
-
|
53
|
-
if (!IsClickButton)
|
54
|
-
|
55
|
-
{
|
56
|
-
|
57
|
-
_rubiksize = int.Parse(_setupForm._rubikSize);
|
58
|
-
|
59
|
-
_tempDigitLabel = new string[_rubiksize];
|
60
|
-
|
61
|
-
CreateRubikCube();
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
private void backToSetupbutton_Click(object sender, EventArgs e)
|
72
|
-
|
73
|
-
{
|
74
|
-
|
75
|
-
IsClickButton=false;
|
76
|
-
|
77
|
-
_setupForm.ShowDialog();
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
private void CreateRubikCube()
|
84
|
-
|
85
|
-
{
|
86
|
-
|
87
|
-
int tempCreateRubikCube = _rubiksize / 2;
|
88
|
-
|
89
|
-
_digitLabelSize = 50;
|
90
|
-
|
91
|
-
var startDigitLabelX = Width / 2 - (tempCreateRubikCube * _digitLabelSize);
|
92
|
-
|
93
|
-
var startDigitLabelY = Height / 2 - (tempCreateRubikCube * _digitLabelSize) - 50;
|
94
|
-
|
95
|
-
digitLabel = new Label[_rubiksize * _rubiksize];
|
96
|
-
|
97
|
-
moveVerticalUpButton = new Button[_rubiksize];
|
98
|
-
|
99
|
-
moveVerticalDownButton = new Button[_rubiksize];
|
100
|
-
|
101
|
-
moveHorizonLeftButton = new Button[_rubiksize];
|
102
|
-
|
103
|
-
moveHorizonRightButton = new Button[_rubiksize];
|
104
|
-
|
105
|
-
SuspendLayout();
|
106
|
-
|
107
|
-
for (var i = 0; i < _rubiksize; i++)
|
108
|
-
|
109
|
-
{
|
110
|
-
|
111
|
-
for (var j = 0; j < _rubiksize; j++)
|
112
|
-
|
113
|
-
{
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
//数字配置
|
118
|
-
|
119
|
-
digitLabel[j + _rubiksize * i] = new Label();
|
120
|
-
|
121
|
-
digitLabel[j + _rubiksize * i].Text = (1 + j + _rubiksize * i).ToString();
|
122
|
-
|
123
|
-
digitLabel[j + _rubiksize * i].Location = new Point(startDigitLabelX + j * _digitLabelSize,
|
124
|
-
|
125
|
-
startDigitLabelY + i * _digitLabelSize);
|
126
|
-
|
127
|
-
digitLabel[j + _rubiksize * i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
128
|
-
|
129
|
-
digitLabel[j + _rubiksize * i].TextAlign = ContentAlignment.MiddleCenter;
|
130
|
-
|
131
|
-
digitLabel[j + _rubiksize * i].Font = new Font("MS UI Gothic", 18, FontStyle.Bold);
|
132
|
-
|
133
|
-
Controls.Add(digitLabel[j + _rubiksize * i]);
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
//ボタン配置
|
140
|
-
|
141
|
-
//上
|
142
|
-
|
143
|
-
moveVerticalUpButton[i] = new Button();
|
144
|
-
|
145
|
-
moveVerticalUpButton[i].Text = "↓";
|
146
|
-
|
147
|
-
moveVerticalUpButton[i].Name = i.ToString();
|
148
|
-
|
149
|
-
moveVerticalUpButton[i].Location =
|
150
|
-
|
151
|
-
new Point(startDigitLabelX + i * _digitLabelSize,
|
152
|
-
|
153
|
-
startDigitLabelY - _digitLabelSize);
|
154
|
-
|
155
|
-
moveVerticalUpButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
156
|
-
|
157
|
-
moveVerticalUpButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
158
|
-
|
159
|
-
moveVerticalUpButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
160
|
-
|
161
|
-
moveVerticalUpButton[i].Click += new EventHandler(MoveUp_Click);
|
162
|
-
|
163
|
-
//下
|
164
|
-
|
165
|
-
moveVerticalDownButton[i] = new Button();
|
166
|
-
|
167
|
-
moveVerticalDownButton[i].Text = "↑";
|
168
|
-
|
169
|
-
moveVerticalDownButton[i].Name = i.ToString();
|
170
|
-
|
171
|
-
moveVerticalDownButton[i].Location =
|
172
|
-
|
173
|
-
new Point(startDigitLabelX + i * _digitLabelSize,
|
174
|
-
|
175
|
-
startDigitLabelY + (_rubiksize * _digitLabelSize));
|
176
|
-
|
177
|
-
moveVerticalDownButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
178
|
-
|
179
|
-
moveVerticalDownButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
180
|
-
|
181
|
-
moveVerticalDownButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
182
|
-
|
183
|
-
moveVerticalDownButton[i].Click += new EventHandler(MoveDown_Click);
|
184
|
-
|
185
|
-
//左
|
186
|
-
|
187
|
-
moveHorizonLeftButton[i] = new Button();
|
188
|
-
|
189
|
-
moveHorizonLeftButton[i].Text = "→";
|
190
|
-
|
191
|
-
moveHorizonLeftButton[i].Name = i.ToString();
|
192
|
-
|
193
|
-
moveHorizonLeftButton[i].Location =
|
194
|
-
|
195
|
-
new Point(startDigitLabelX - _digitLabelSize,
|
196
|
-
|
197
|
-
startDigitLabelY + i * _digitLabelSize);
|
198
|
-
|
199
|
-
moveHorizonLeftButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
200
|
-
|
201
|
-
moveHorizonLeftButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
202
|
-
|
203
|
-
moveHorizonLeftButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
204
|
-
|
205
|
-
moveHorizonLeftButton[i].Click += new EventHandler(MoveLeft_Click);
|
206
|
-
|
207
|
-
//右
|
208
|
-
|
209
|
-
moveHorizonRightButton[i] = new Button();
|
210
|
-
|
211
|
-
moveHorizonRightButton[i].Text = "←";
|
212
|
-
|
213
|
-
moveHorizonRightButton[i].Name = i.ToString();
|
214
|
-
|
215
|
-
moveHorizonRightButton[i].Location =
|
216
|
-
|
217
|
-
new Point(startDigitLabelX + (_rubiksize * _digitLabelSize),
|
218
|
-
|
219
|
-
startDigitLabelY + i * _digitLabelSize);
|
220
|
-
|
221
|
-
moveHorizonRightButton[i].Size = new Size(_digitLabelSize, _digitLabelSize);
|
222
|
-
|
223
|
-
moveHorizonRightButton[i].TextAlign = ContentAlignment.MiddleCenter;
|
224
|
-
|
225
|
-
moveHorizonRightButton[i].Font = new Font("MS UI Gothic", 18, FontStyle.Regular);
|
226
|
-
|
227
|
-
moveHorizonRightButton[i].Click += new EventHandler(MoveRight_Click);
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
Controls.AddRange(moveVerticalUpButton);
|
232
|
-
|
233
|
-
Controls.AddRange(moveVerticalDownButton);
|
234
|
-
|
235
|
-
Controls.AddRange(moveHorizonLeftButton);
|
236
|
-
|
237
|
-
Controls.AddRange(moveHorizonRightButton);
|
238
|
-
|
239
|
-
ResumeLayout();
|
240
|
-
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
private int _clickButtonNum;
|
246
|
-
|
247
|
-
private string[] _tempDigitLabel;
|
248
|
-
|
249
|
-
private void MoveUp_Click(object sender, EventArgs e)
|
250
|
-
|
251
|
-
{
|
252
|
-
|
253
|
-
IsClickButton = true;
|
254
|
-
|
255
|
-
_clickButtonNum = int.Parse(((Button)sender).Name);
|
256
|
-
|
257
|
-
label2.Text = ((Button)sender).Name;
|
258
|
-
|
259
|
-
for (var i = 0; i < _rubiksize; i++)
|
260
|
-
|
261
|
-
{
|
262
|
-
|
263
|
-
_tempDigitLabel[i] = digitLabel[_clickButtonNum + i * _rubiksize].Text;
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
for (var i = 0; i < _rubiksize; i++)
|
268
|
-
|
269
|
-
{
|
270
|
-
|
271
|
-
if (i == 0)
|
272
|
-
|
273
|
-
{
|
274
|
-
|
275
|
-
digitLabel[_clickButtonNum + i * _rubiksize].Text = _tempDigitLabel[_rubiksize - 1];
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
else
|
280
|
-
|
281
|
-
digitLabel[_clickButtonNum + i * _rubiksize].Text = _tempDigitLabel[i - 1];
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
private void MoveDown_Click(object sender, EventArgs e)
|
292
|
-
|
293
|
-
{
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
private void MoveLeft_Click(object sender, EventArgs e)
|
302
|
-
|
303
|
-
{
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
private void MoveRight_Click(object sender, EventArgs e)
|
312
|
-
|
313
|
-
{
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
}
|
324
|
-
|
325
|
-
```
|
326
|
-
|
327
323
|
```### 前提・実現したいこと
|
328
324
|
|
329
325
|
今年のLINEのインターンシップのコーディングテストであったような二次元ルービックキューブを作ろうとしており、動作としては、各列・行にあるボタンをクリックするとクリックした列もしくは行が縦・横に一つずつずれるというものです。しかし上に配置したボタン(Text="↓"のボタンです)をクリックしても列がずれません。ずれるはずの列の各Label(ここではdigitLabel)のTextプロパティの文字はしっかりとずれているのですが画面上に反映されません。
|
1
コードを```で囲いました。初めての利用でわからないことが多いもので、、
test
CHANGED
File without changes
|
test
CHANGED
@@ -106,11 +106,13 @@
|
|
106
106
|
|
107
107
|
for (var i = 0; i < _rubiksize; i++)
|
108
108
|
|
109
|
+
{
|
110
|
+
|
109
111
|
for (var j = 0; j < _rubiksize; j++)
|
110
112
|
|
111
113
|
{
|
112
114
|
|
113
|
-
|
115
|
+
|
114
116
|
|
115
117
|
//数字配置
|
116
118
|
|
@@ -320,7 +322,7 @@
|
|
320
322
|
|
321
323
|
}
|
322
324
|
|
323
|
-
|
325
|
+
```
|
324
326
|
|
325
327
|
```### 前提・実現したいこと
|
326
328
|
|