Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新winforms Paint。每秒添加一次_Winforms_F# - Fatal编程技术网

更新winforms Paint。每秒添加一次

更新winforms Paint。每秒添加一次,winforms,f#,Winforms,F#,我正在尝试制作一个带有秒计数器的小应用程序,它在一个圆圈中每秒顺时针旋转一次。我已经找出了许多部分,但不能得到线更新每一秒,因为我希望。我在下面粘贴了一个MWE,它只是将手旋转90度。我希望它每秒旋转360/60*s(其中s是当前秒) 我已经尝试了很多使用timer对象的方法(见下面的几行),但都没有效果。任何帮助都将不胜感激 open System.Windows.Forms open System.Drawing // Prepare window form let win = new S

我正在尝试制作一个带有秒计数器的小应用程序,它在一个圆圈中每秒顺时针旋转一次。我已经找出了许多部分,但不能得到线更新每一秒,因为我希望。我在下面粘贴了一个MWE,它只是将手旋转90度。我希望它每秒旋转360/60*s(其中s是当前秒)

我已经尝试了很多使用timer对象的方法(见下面的几行),但都没有效果。任何帮助都将不胜感激

open System.Windows.Forms
open System.Drawing

// Prepare window form
let win = new System.Windows.Forms.Form ()
// Set some properties
win.BackColor <- System.Drawing.Color.White
let height = 250
let width = 200
win.Size <- System.Drawing.Size (width, height)

// make a timer 
let timer = new Timer ()
timer.Interval <- 1000 // create an event every 1000 millisecond 
timer.Enabled <- true // activate the timer

let getEndPoint degrees =
  let t = float 50
  let s = float 0
  let theta = float degrees * (System.Math.PI / float 180)
  let u = (s * (cos theta) + t * (sin theta)) + float 100
  let v = (-s * (sin theta) + -t * (cos theta)) + float 100
  Point (int u,int v)

// Set paint call-back function
let paint (e : PaintEventArgs) (x) : unit = 
    let pen = new Pen (Color.Black)
    let endPoint = getEndPoint x
    let points = [|Point (100,100); endPoint|] 
    e.Graphics.DrawLines (pen, points)

let getDegrees =
  360/60*System.DateTime.Now.Second

let addPaint degrees =
  printfn "Draws with degrees %A" degrees
  win.Paint.Add (fun e -> (paint e degrees))

win.Paint.Add (fun e -> (paint e 90))
//timer.Tick.Add (fun e -> (addPaint 90)) // Doesn't draw
//timer.Tick.Add (fun e -> (addPaint getDegrees)) // Doesn't draw, updates every second, but doesn't change degrees 
//timer.Tick.Add (fun e -> (addPaint (360/60*System.DateTime.Now.Second))) // Doesn't draw, but get correct degrees 

// Start the event-loop.
System.Windows.Forms.Application.Run win
open System.Windows.Forms
开放系统.绘图
//准备窗口表格
let win=new System.Windows.Forms.Form()
//设置一些属性

win.BackColor使用以下两行解决了问题:

win.Paint.Add (fun e -> (paint e (360/60*System.DateTime.Now.Second)))
timer.Tick.Add (fun e -> win.Invalidate())

提示:getDegrees不是代码中的函数