这是我的代码的样子:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FJBch09ex10
{
public partial class Form1 : Form
{
Random r = new Random();
int num = r.Next(0, 100);
int counter = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn1_Click(object sender, EventArgs e)
{
counter++;
if (int.Parse(txt1.Text) > num)
{
lbl1.Text = "the number is too high";
Form1.BackColor = HotTrack;
}
else {
lbl1.Text = "the number is too low";
Form1.BackColor = MenuHighlight;
}
}
}
}
目前 r.Next 中的 r 正在运行错误。Form1.BackColor 尝试也都是运行错误。知道为什么这些是运行错误吗?r 表示“字段初始值设定项无法引用非静态字段......”Form1 表示“非静态字段需要对象引用......”