[問題] 物件屬性
先奉上程式碼
public partial class Form1 : Form
{
Label[]led = new Label[7];
int a=1;
int count
public Form1()
{
InitializeComponent();
timer1.Enabled = true;
timer1.Interval = 500;
label9.Text = "旋轉: 順時針";
private void button2_Click(object sender, EventArgs e)
{
count = 0;
if (count < 7)
{
led[count + 1].BackColor = Color.Red;
led[count].BackColor = Color.Gray;
count++;
}
else
{
led[0].BackColor = Color.Red;
led[7].BackColor = Color.Gray;
count = 0;
}
timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (a==1)
{
label9.Text = "旋轉: 逆時針";
a = 0;
}
else
{
label9.Text = "旋轉: 順時針";
a = 1;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (a==1)
{
if (count < 7)
{
led[count + 1].BackColor =Color.Red;
led[count].BackColor = Color.Gray;
count++;
}
else
{
led[0].BackColor = Color.Red;
led[7].BackColor = Color.Gray;
count = 0;
}
}
else
if (count > 0)
{
led[count - 1].BackColor = Color.Red;
led[count].BackColor = Color.Gray;
count--;
}
else
{
led[7].BackColor = Color.Red;
led[0].BackColor = Color.Gray;
count = 7;
}
}
這個程式,按偵錯時,在這一行""led[count + 1].BackColor =Color.Red;""
會出現這個問題""並未將物件參考設定為物件的執行個體""
感覺上是沒有創造出Label這一個物件,所以無法控制BackColor這一個屬性
拜託板上的各路高手了,這個程式已經想好幾天了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.35.223.137
→
01/06 20:34, , 1F
01/06 20:34, 1F
→
01/06 20:35, , 2F
01/06 20:35, 2F
→
01/06 20:35, , 3F
01/06 20:35, 3F
→
01/06 20:36, , 4F
01/06 20:36, 4F
→
01/06 20:39, , 5F
01/06 20:39, 5F
→
01/06 20:41, , 6F
01/06 20:41, 6F
→
01/06 20:41, , 7F
01/06 20:41, 7F
→
01/06 20:41, , 8F
01/06 20:41, 8F
→
01/06 20:41, , 9F
01/06 20:41, 9F
→
01/11 12:01, , 10F
01/11 12:01, 10F