private void ShowRandomLetter() { char letter = GetRandomLetter(); int x = random.Next(label1.Width - 20); int y = random.Next(0, label1.Height - 20); int r = random.Next(256); int g = random.Next(256); int b = random.Next(256); label1.Text = letter.ToString(); label1.ForeColor = Color.FromArgb(r, g, b); label1.Location = new Point(x, y); }这段代码提示int y = random.Next(0, label1.Height - 20);minvalue不能大于maxvalue
时间: 2024-01-24 08:01:54 浏览: 80
您好,根据您提供的信息,这段代码中 `random.Next()` 方法的第一个参数是最小值,第二个参数是最大值,因此应该将 `random.Next(0, label1.Height - 20)` 修改为 `random.Next(label1.Height - 20)`,即:
```
private void ShowRandomLetter()
{
char letter = GetRandomLetter();
int x = random.Next(label1.Width - 20);
int y = random.Next(label1.Height - 20);
int r = random.Next(256);
int g = random.Next(256);
int b = random.Next(256);
label1.Text = letter.ToString();
label1.ForeColor = Color.FromArgb(r, g, b);
label1.Location = new Point(x, y);
}
```
这样就可以避免报错了。
阅读全文