Using System.Windows.Forms.Timer

本文介绍如何利用System.Windows.Forms.Timer替代MAXScript的rollout Timer控件,实现定期调用MAXScript函数的功能。这种方法的优势在于无需使用rollout即可实现定时任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The following example demonstrates

  • The use of the System.Windows.Forms.Timer DotNetObject as alternative to the MAXScript rollout Timer control.
  • The main advantage of the DotNet version is the ability to call MAXScript functions at given intervals without the need for a rollout.
MAXSCRIPT CODE:
theTimer = dotNetObject "System.Windows.Forms.Timer" --create a Timer
fn printTime = (print localTime) --define a MAXScript function to be called by the Timer.
dotnet.addEventHandler theTimer "tick" printTime --add ON TICK event hander to call the function
theTimer.interval = 1000 --set the tick interval to 1 second (1000 milliseconds)
theTimer.start() --start the Timer
--theTimer.stop() --use this method to stop the Timer.
RESULT:
dotNetObject:System.Windows.Forms.Timer
printTime()
OK
1000
undefined
"10/20/2006 1:11:28 PM"
"10/20/2006 1:11:29 PM"
"10/20/2006 1:11:30 PM"
"10/20/2006 1:11:31 PM"
...
partial class MainForm { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.lstServers = new System.Windows.Forms.ListBox(); this.lstNodes = new System.Windows.Forms.ListBox(); this.lstItems = new System.Windows.Forms.ListBox(); this.txtValues = new System.Windows.Forms.TextBox(); this.txtWriteValue = new System.Windows.Forms.TextBox(); this.btnConnect = new System.Windows.Forms.Button(); this.btnDisconnect = new System.Windows.Forms.Button(); this.btnBrowse = new System.Windows.Forms.Button(); this.btnAddItem = new System.Windows.Forms.Button(); this.btnStartRead = new System.Windows.Forms.Button(); this.btnStopRead = new System.Windows.Forms.Button(); this.btnWrite = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.SuspendLayout(); // 控件布局代码... // 这里添加实际的布局代码(位置、大小等) this.ResumeLayout(false); this.PerformLayout(); } // 控件声明 private ListBox lstServers; private ListBox lstNodes; private ListBox lstItems; private TextBox txtValues; private TextBox txtWriteValue; private Button btnConnect; private Button btnDisconnect; private Button btnBrowse; private Button btnAddItem; private Button btnStartRead; private Button btnStopRead; private Button btnWrite; private Label label1; private Label label2; private Label label3; private Label label4; } 引用这段代码帮我改一下我的代码以下是我的代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace mjh.OPCClient.sil { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } } }
最新发布
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值