110,538
社区成员
发帖
与我相关
我的任务
分享
Label1.ForeColor = Color.Red;
在label1的textchanged事件里写代码:
Label1.ForeColor = Color.Green;
timer1.enabled=false;
timer1.enabled=true;
收工。
public class Test {
private double m_OldValue;
private double m_NewValue;
private DateTime m_ChgTime;
public double Value{
get{ return m_newValue; }
set{ m_OldValue = m_NewValue;
m_NewValue = value;
m_ChgTime = DateTime.Now;
}
}
//判断 Value 的值, 在 6秒内 是否变化
public bool IsChgIn6Skd{
get{ return (DateTime.Now-m_ChgTime).TotalSeconds>=6; }
}
}
static void Main(string[] args)
{
MyTest mt = new MyTest();
mt.myAction = Say;
Thread.Sleep(1000);
Console.WriteLine("第一次变更-----------");
mt.Name = "Hello ";
Thread.Sleep(7000);
Console.WriteLine("第二次变更-----------");
mt.Name = "World";
Console.ReadLine();
}
public static void Say(long milliseconds)
{
if(milliseconds<6000)
Console.WriteLine("小于6秒");
else
Console.WriteLine("大于6秒");
}
public class MyTest
{
private Stopwatch sw;
public Action<long> myAction;
public MyTest()
{
sw = new Stopwatch();
sw.Restart();
}
private string name;
public string Name
{
get { return name; }
set {
name = value;
myAction(sw.ElapsedMilliseconds);
}
}
}
static void Main(string[] args)
{
MyTest mt = new MyTest();
mt.myAction = Say;
Console.WriteLine("第一次变更-----------");
mt.Name = "Hello ";
Console.WriteLine("第二次变更-----------");
mt.Name = "World";
Console.ReadLine();
}
public static void Say()
{
Console.WriteLine("属性变更啦");
}
public class MyTest
{
public Action myAction;
private string name;
public string Name
{
get { return name; }
set { name = value; myAction(); }
}
}