質問編集履歴
1
内容の修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
C# テキストボックスに入力
|
1
|
+
C# テキストボックスに入力した数値の範囲限定
|
test
CHANGED
@@ -1,7 +1,221 @@
|
|
1
|
+
迷路を自動生成するものをつくっていて、縦と横の長さ、出入り口の数の数値を入力し
|
2
|
+
|
3
|
+
フォーム内に設置したボタンをクリックすると
|
4
|
+
|
1
|
-
|
5
|
+
その数値に応じた長さの線が描画されるようにしているのですが、その数値の範囲を限定させたいのです。
|
2
|
-
|
6
|
+
|
7
|
+
|
8
|
+
|
3
|
-
|
9
|
+
範囲の限定についてですが、
|
4
|
-
|
10
|
+
|
5
|
-
|
11
|
+
・入力する数値の最大最小を決めて、その範囲外の数字や文字が入力されても実行画面では反応はないようにしたい。
|
12
|
+
|
6
|
-
|
13
|
+
・範囲内の数値が入力されたときのみ応答がある。
|
14
|
+
|
15
|
+
・範囲は最小2から最大50まで、出入り口は最小2から最大4までを考えている。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
以下は現在のコードです。
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
private void CreateSoto()
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
private int tate;
|
30
|
+
|
31
|
+
private int yoko;
|
32
|
+
|
33
|
+
private int deiriguti;
|
34
|
+
|
35
|
+
private int x_start;
|
36
|
+
|
37
|
+
private int x_end;
|
38
|
+
|
39
|
+
private int y_start;
|
40
|
+
|
41
|
+
private int y_end;
|
42
|
+
|
43
|
+
private Image _img;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
string s = this.textBox1.Text;
|
48
|
+
|
49
|
+
string a = this.textBox2.Text;
|
50
|
+
|
51
|
+
string d = this.textBox3.Text;
|
52
|
+
|
53
|
+
int result;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
if (int.TryParse(s, out result))
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
tate = result;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
if (int.TryParse(a, out result))
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
yoko = result;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
if (int.TryParse(d, out result))
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
deiriguti = result;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
//テキストボックス入力で枠線の値を変更
|
88
|
+
|
89
|
+
float x_start = (yoko * 20);
|
90
|
+
|
91
|
+
float y_start = (tate * 20);
|
92
|
+
|
93
|
+
float y_end = (tate * 20) + 10;
|
94
|
+
|
95
|
+
float x_end = (yoko * 20) + 10;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
// pictureboxのサイズを変更
|
100
|
+
|
101
|
+
this.pictureBox1.Width = 10 + (int)x_end + 10;
|
102
|
+
|
103
|
+
this.pictureBox1.Height = 10 + (int)y_end + 10;
|
104
|
+
|
105
|
+
|
106
|
+
|
7
|
-
|
107
|
+
Bitmap bmp = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
|
108
|
+
|
109
|
+
//ImageオブジェクトのGraphicsオブジェクトを作成する
|
110
|
+
|
111
|
+
Graphics g = Graphics.FromImage(bmp);
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
//出入り口の数を設定
|
118
|
+
|
119
|
+
switch (deiriguti)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
case 2:
|
124
|
+
|
125
|
+
//左の枠線
|
126
|
+
|
127
|
+
g.DrawLine(Black, 10, 30, 10, y_end);//x始点は固定
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//右の枠線
|
132
|
+
|
133
|
+
g.DrawLine(Black, x_end, 10, x_end, y_end - 20);//y始点は固定
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
//上の枠線
|
138
|
+
|
139
|
+
g.DrawLine(Black, 10, 10, x_end, 10);//始点と終点yは固定
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
//下の枠線
|
144
|
+
|
145
|
+
g.DrawLine(Black, 10, y_end, x_end, y_end);
|
146
|
+
|
147
|
+
break;
|
148
|
+
|
149
|
+
case 3:
|
150
|
+
|
151
|
+
//左の枠線
|
152
|
+
|
153
|
+
g.DrawLine(Black, 10, 30, 10, y_end);//x始点は固定
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//右の枠線
|
158
|
+
|
159
|
+
g.DrawLine(Black, x_end, 10, x_end, y_end - 20);//y始点は固定
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
//上の枠線
|
164
|
+
|
165
|
+
g.DrawLine(Black, 10, 10, x_end - 20, 10);//始点と終点yは固定
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//下の枠線
|
170
|
+
|
171
|
+
g.DrawLine(Black, 10, y_end, x_end, y_end);
|
172
|
+
|
173
|
+
break;
|
174
|
+
|
175
|
+
case 4:
|
176
|
+
|
177
|
+
//左の枠線
|
178
|
+
|
179
|
+
g.DrawLine(Black, 10, 30, 10, y_end);//x始点は固定
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
//右の枠線
|
184
|
+
|
185
|
+
g.DrawLine(Black, x_end, 10, x_end, y_end - 20);//y始点は固定
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
//上の枠線
|
190
|
+
|
191
|
+
g.DrawLine(Black, 10, 10, x_end - 20, 10);//始点と終点yは固定
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
//下の枠線
|
196
|
+
|
197
|
+
g.DrawLine(Black, 30, y_end, x_end, y_end);
|
198
|
+
|
199
|
+
break;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
//リソースを解放する
|
206
|
+
|
207
|
+
g.Dispose();
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
//PictureBox1に表示する
|
212
|
+
|
213
|
+
pictureBox1.Image = bmp;
|
214
|
+
|
215
|
+
_img = bmp;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
```
|