回答編集履歴

1

サンプルコードを追記

2019/04/15 20:59

投稿

nskydiving
nskydiving

スコア6500

test CHANGED
@@ -3,3 +3,105 @@
3
3
 
4
4
 
5
5
  変数「s」が宣言されていないか、宣言している場所が正しくないときに出るエラーですので、ご確認ください。
6
+
7
+
8
+
9
+ #### 追記
10
+
11
+
12
+
13
+ Form2 に Form1 の参照を持たせておけば、Form1 の状態を見て Form2 の処理を変えることはできると思います。
14
+
15
+
16
+
17
+ そもそも、ユーザーに 2 つのフォームを同時に操作させるのはアプリケーションの使い勝手としてどうなのか?という疑問はありますが。
18
+
19
+
20
+
21
+ ```C#
22
+
23
+ using System;
24
+
25
+
26
+
27
+ namespace Sample
28
+
29
+ {
30
+
31
+ public int S { get; set; }
32
+
33
+
34
+
35
+ public class Form1
36
+
37
+ {
38
+
39
+ private void timer1_Tick(object sender, EventArgs e)
40
+
41
+ {
42
+
43
+ c++;
44
+
45
+ fm3.label1.Text = r.Next(1, 100).ToString();
46
+
47
+ number[s] = Convert.ToInt32(fm3.label1.Text);
48
+
49
+ this.S++;
50
+
51
+ if (Convert.ToInt32(comboBox1.Text) + 1 == c)
52
+
53
+ {
54
+
55
+ timer1.Enabled = false;
56
+
57
+ fm3.Hide();
58
+
59
+ this.S = r.Next(1, c - 1);
60
+
61
+ fm2.label1.Text = this.S + "枚目のカードの数字は?";
62
+
63
+ fm2.ShowDialog();
64
+
65
+ }
66
+
67
+ }
68
+
69
+ }
70
+
71
+
72
+
73
+ public class Form2
74
+
75
+ {
76
+
77
+ private form1;
78
+
79
+
80
+
81
+ public Form2(Form1 form1)
82
+
83
+ {
84
+
85
+ this.form1 = form1;
86
+
87
+ }
88
+
89
+
90
+
91
+ private void button1_Click(object sender, EventArgs e)
92
+
93
+ {
94
+
95
+ if (number[this.form1.S] == Convert.ToInt32(fm2.textBox1.Text))
96
+
97
+ {
98
+
99
+ }
100
+
101
+ }
102
+
103
+ }
104
+
105
+ }
106
+
107
+ ```