NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 11757|回复: 7
打印 上一主题 下一主题

[个人作品] vb中timer的event

[复制链接]
跳转到指定楼层
1m
发表于 2011-3-8 15:05:48 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 panhao1 于 2011-3-9 23:34 编辑

本来是grasshopper视屏教程要出的关于委托和多线程的内容,这里辉哥要得急,简单点说下

首先是要声明timer类 这里声明就有两种 先说第一种

直接声明 和C#一样
  Private Sub RunScript(ByVal x As Boolean, ByVal y As Object, ByRef A As Object)
    'your code goes here…

    If s Then
  timer = New System.Windows.Forms.Timer
    timer.Interval = 100
    AddHandler timer.Tick, AddressOf Timer_Tick

      timer.Start()
      s = False
    End If
    A = int

  End Sub
  '<Custom additional code>
  Dim timer As  System.Windows.Forms.Timer
  Dim int As int32 = 0
  Dim s As Boolean = True
  Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    int += 1
    If int > 100  Then timer.Stop():int = 0
    owner.ExpireSolution(True)
  End Sub

但是不幸的是C#可以直接+=来添加委托
而vb必须要AddHandler关键字

再就是第二种声明

Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object)
    If s Then
      timer = New System.Windows.Forms.Timer
      timer.Interval = 100
      timer.Start()
      s = False
    End If
    A = int
  End Sub
'<Custom additional code>

  Private WithEvents timer As System.Windows.Forms.Timer
  Dim int As int32 = 0
  Dim s As Boolean = True
  Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles timer.tick
    int += 1
    If int > 100  Then timer.Stop():int = 0
    owner.ExpireSolution(True)
  End Sub

WithEvents 来声明一个带事件的类 然后用handles来接委托


看不懂没关系 复制代码就可以用
timer会从0跑到100停下来
timer。start和timer。stop可以自己设置条件
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-5-16 15:33 , Processed in 0.282354 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表