2016-05-20 14 views
0

Setup definiert: mono 4.5, Linux, f # 4.0, gtk #mit GTK # DrawingArea in F #: ExposeEvent nicht

mein Code hier, vor allem aus Probe Schnipsel kopiert:

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 

Es schlägt fehl, zu kompilieren mit folgendem Fehler:

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

Antwort

0

Entpuppte sich als gtk2 -> gtk3 difference. Hier ist der aktualisierte Code - DrawingArea gibt nun Drawn und nicht ExposeEvent aus

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()