在 F# 中使用 Gtk# DrawingArea:未定义 ExposeEvent

Using Gtk# DrawingArea in F#: ExposeEvent not defined

设置:单声道 4.5,linux,f# 4.0,gtk#

这是我的代码,主要是从示例片段中复制的:

open System
open Gtk

let (width, height) = (800, 600)

[<EntryPoint>]
let main argv =
  Application.Init ()
  let window = new Window ("helloworld")

  window.SetDefaultSize(width, height)
  window.DeleteEvent.Add(fun e -> window.Hide(); Application.Quit(); e.RetVal <- true)

  let drawing = new Gtk.DrawingArea () 
  drawing.ExposeEvent.Add(fun x ->
    let gc = drawing.Style.BaseGC(StateType.Normal)
    let allocColor (r,g,b) =
       let col = ref (Gdk.Color(r,g,b))
       let _ = gc.Colormap.AllocColor(col, true, true)
       !col
    gc.Foreground <- allocColor (255uy, 0uy, 0uy)
    drawing.GdkWindow.DrawLine(gc, 0, 0, 100, 100)
    )
  window.Add(drawing)
  window.ShowAll()
  window.Show()
  Application.Run ()
  0

编译失败,出现以下错误:

The field, constructor or member 'ExposeEvent' is not defined

竟然是一个gtk2 -> gtk3 difference。这是更新后的代码 - DrawingArea 现在发出 Drawn 而不是 ExposeEvent

open System
open Gtk
open Cairo

let (width, height) = (800, 600)

[<EntryPoint>]
let main argv =
  Application.Init ()
  let window = new Window ("helloworld")

  window.SetDefaultSize(width, height)
  window.DeleteEvent.Add(fun e -> window.Hide(); Application.Quit(); e.RetVal <- true)

  let drawing = new Gtk.DrawingArea () 
  drawing.Drawn.Add(fun args ->
    let cr = args.Cr
    cr.MoveTo(0.0, 0.0)
    cr.LineTo(100.0, 100.0)
    cr.LineWidth = 1.0
    cr.Stroke ()
    ) 
  window.Add(drawing)
  window.ShowAll()
  window.Show()
  Application.Run ()