【发布时间】:2018-01-15 03:35:08
【问题描述】:
作为 F# 的新手,我试图了解如何在由计时器事件触发的表单中进行图形更新。
我的期望是下面的简单例程应该每秒继续绘制新的“随机”线。
在定时器事件之外调用line() 似乎没有任何问题,但我无法理解为什么当通过定时器事件调用相同的函数时屏幕上什么也没有显示。
open System
open System.Drawing
open System.Windows.Forms
let form = new Form(Text="Simple Animation", Size=Size(400,500))
let pen = new Pen(Color.Red, 4.0f)
let random = new Random()
let line x =
let flexRight = random.Next(29,300)
form.Paint.Add (fun e -> e.Graphics.DrawLine(pen, 30, 30, 350, flexRight))
let timer=new Timer(Interval=1000, Enabled=true)
timer.Tick.Add(fun time -> line())
form.Show()
Application.Run(form)
非常感谢任何帮助,谢谢。
【问题讨论】:
-
Timer的完整类型是什么?
标签: timer f# system.drawing.graphics