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

回答編集履歴

1

見直しキャンペーン中

2023/07/27 16:31

投稿

TN8001
TN8001

スコア10108

answer CHANGED
@@ -1,68 +1,68 @@
1
- コードを提示する場合は、できるだけコンパイルが通る形でお願いしたいです。
2
-
3
- * `frmStart.Show()` どっかで作った`frmStart`クラスのインスタンス?それともstaticメソッド??
4
- * `var timer`の行のようにメソッド外に処理が書いてある
5
- * `This.close()`って何?
6
-
7
- イベントハンドラ等がstaticですが、これは意図してやってるんでしょうか?
8
-
9
- 少なくとも普通に作った場合は、想定通り閉じます。
10
-
11
- ```C#
12
- using System;
13
- using System.Windows.Forms;
14
-
15
- namespace Questions347963
16
- {
17
- public partial class Form1 : Form
18
- {
19
- public Form1()
20
- {
21
- InitializeComponent();
22
- Load += Form1_Load;
23
- }
24
-
25
- private void Form1_Load(object sender, EventArgs e)
26
- => new Form2().Show();
27
- }
28
- }
29
- ```
30
-
31
- ```C#
32
- using System;
33
- using System.Diagnostics;
34
- using System.Windows.Forms;
35
-
36
- namespace Questions347963
37
- {
38
- public partial class Form2 : Form
39
- {
40
- private int countDown;
41
- private readonly Timer myTimer = new Timer { Interval = 1000, };
42
-
43
- public Form2()
44
- {
45
- InitializeComponent();
46
- Load += Form2_Load;
47
- }
48
-
49
- private void Form2_Load(object sender, EventArgs e)
50
- {
51
- myTimer.Tick += MyTimer_Tick;
52
- myTimer.Start();
53
- }
54
-
55
- private void MyTimer_Tick(object sender, EventArgs e)
56
- {
57
- countDown++;
58
- Debug.WriteLine(countDown);
59
- if (countDown >= 15)
60
- {
61
- Debug.WriteLine("15秒経過したので終了");
62
- myTimer.Stop();
63
- Close();
64
- }
65
- }
66
- }
67
- }
1
+ コードを提示する場合は、できるだけコンパイルが通る形でお願いしたいです。
2
+
3
+ * `frmStart.Show()` どっかで作った`frmStart`クラスのインスタンス?それともstaticメソッド??
4
+ * `var timer`の行のようにメソッド外に処理が書いてある
5
+ * `This.close()`って何?
6
+
7
+ イベントハンドラ等がstaticですが、これは意図してやってるんでしょうか?
8
+
9
+ 少なくとも普通に作った場合は、想定通り閉じます。
10
+
11
+ ```cs
12
+ using System;
13
+ using System.Windows.Forms;
14
+
15
+ namespace Questions347963
16
+ {
17
+ public partial class Form1 : Form
18
+ {
19
+ public Form1()
20
+ {
21
+ InitializeComponent();
22
+ Load += Form1_Load;
23
+ }
24
+
25
+ private void Form1_Load(object sender, EventArgs e)
26
+ => new Form2().Show();
27
+ }
28
+ }
29
+ ```
30
+
31
+ ```cs
32
+ using System;
33
+ using System.Diagnostics;
34
+ using System.Windows.Forms;
35
+
36
+ namespace Questions347963
37
+ {
38
+ public partial class Form2 : Form
39
+ {
40
+ private int countDown;
41
+ private readonly Timer myTimer = new Timer { Interval = 1000, };
42
+
43
+ public Form2()
44
+ {
45
+ InitializeComponent();
46
+ Load += Form2_Load;
47
+ }
48
+
49
+ private void Form2_Load(object sender, EventArgs e)
50
+ {
51
+ myTimer.Tick += MyTimer_Tick;
52
+ myTimer.Start();
53
+ }
54
+
55
+ private void MyTimer_Tick(object sender, EventArgs e)
56
+ {
57
+ countDown++;
58
+ Debug.WriteLine(countDown);
59
+ if (countDown >= 15)
60
+ {
61
+ Debug.WriteLine("15秒経過したので終了");
62
+ myTimer.Stop();
63
+ Close();
64
+ }
65
+ }
66
+ }
67
+ }
68
68
  ```