在用户定义的类中,我有一个计时器,但它不会在我启动时启动Timer.Enabled.
用户定义的类:
TSerialIndicator = public class
private
method TxTimerEvent(Sender:System.Object; e:System.EventArgs);
public
Txlight:Label;
Txtimer:System.Windows.Forms.Timer;
constructor(mform:Form);
method Transmit;
method Receive;
end;
这是构造函数:
constructor TSerialIndicator(mform:Form);
begin
TxLight := new Label;
TxLight.AutoSize := false;
TxLight.BorderStyle := BorderStyle.FixedSingle;
TxLight.Location := new point(52,163);
TxLight.Width := 20;
TxLight.Height := 20;
mform.Controls.Add(TxLight);
TxTimer := new System.Windows.Forms.Timer;
TxTimer.Interval:=1;
TxTimer.Enabled:=false;
TxTimer.Tick += new System.EventHandler(@TxTimerEvent);
TxLight.BackColor := Color.Black;
end;
这是定义的传输方法:
method TSerialIndicator.Transmit;
begin
TxLight.BackColor := Color.Red;
if TxTimer.Enabled = false then
TxTimer.Enabled:=true;
end;
这是定义的 TxTimerEvent:
method TSerialIndicator.TxTimerEvent(Sender:System.Object; e:System.EventArgs);
begin
TxLight.BackColor := Color.Black;
TxTimer.Enabled:=false;
end;
以下是它的创建和使用方式:
Slight := new TSerialIndicator(self);
Slight.Transmit;
当我从程序的其他部分调用 Transmit 时,它会做它的事情,但 TxTimerEvent 永远不会触发。我什至尝试过启动/停止它的方法。它仍然没有执行它的 Tick 事件。但是,我确实注意到,当我在构造函数中启用计时器时,它确实会触发一次 TxTimerEvent。
我究竟做错了什么?
提前致谢,