public System.Timers.Timer trime; //定时器
public int count=0; //定时器变量,累加计数时用到
public void A(string a)
{
//主窗体中会调用A方法,给出a的值。
trime = new System.Timers.Timer(1000);
trime.AutoReset = true;//执行一次false,一直执行true;
trime.Enabled = true;//是否执行Elapsed事件
trime.Elapsed += new System.Timers.ElapsedEventHandler(TimerUp);
}
public void TimerUp(object sender, ElapsedEventArgs e)
{
count++;
try
{
foreach (System.Windows.Forms.Control control in mapPictureBox.Controls)
{
//////问: 怎么传递参数,用来代替判断条件中的“1”
if (control.Text.Equals("1")) //控件名称如果为a,则a闪烁
{
this.Invoke((MethodInvoker)delegate
{
if (count % 2 == 0)
{
control.BackColor = System.Drawing.Color.Red;
}
else
{
control.BackColor = System.Drawing.Color.Yellow;
}
});
}
}
HasAlert = true;
}
catch { }
}
请各位大神指点
1.在被调用方法加入两个参数
或
2.在被调用方法传入的参数中加入两个属性,就是你需要的条件
在一个类里面定义一个变量 public static string lampName = "a";
你可以随时修改这个变量
然后就可以判断了
if (control.Text.Equals(Xxx.lampName))
首先你思路出了问题啊,这个事件委托是已经定义好的参数列表,在timer invoke后,只会传出指定的参数,你没法往这个委托的参数列表中添加参数了
你这个只能在外部添加一个变量来控制你的判断了