Skip to content

Instantly share code, notes, and snippets.

@dsyme
Created October 18, 2014 11:35
Show Gist options
  • Save dsyme/d6cc8443797e0d5e2b74 to your computer and use it in GitHub Desktop.
Save dsyme/d6cc8443797e0d5e2b74 to your computer and use it in GitHub Desktop.
Sample of using the Eto cross-platform GUI framework (https://github.com/picoe/Eto/) with F# (on windows)
#r @"packages\Eto.Forms.1.3.0\lib\net40\Eto.dll"
#r @"packages\Eto.Platform.Windows.1.3.0\lib\net40\Eto.Platform.Windows.dll"
open System
open Eto.Forms
open Eto.Drawing
let MyEtoForm() =
let form = new Form(Title = "My Eto Form", ClientSize = new Size(400, 350))
// DynamicLayout is the typical layout to use but you can also use TableLayout or PixelLayout
let layout = new DynamicLayout()
layout.BeginHorizontal() |> ignore
layout.Add(null) |> ignore
layout.Add(new Label(Text = "Hello World!")) |> ignore
layout.Add(null) |> ignore
layout.EndHorizontal()
// scrollable gives you a scrolling region
form.Content <- new Scrollable(Content = layout)
// your commands!
let clickMe = new Command(MenuText = "Click Me!", ShowLabel = true, ToolBarText = "Click Me!")
clickMe.Executed.Add (fun e -> MessageBox.Show(form, "I was clicked!") |> ignore)
let quitAction = new Command(MenuText = "Quit", Shortcut = (Application.Instance.CommonModifier ||| Keys.Q))
quitAction.Executed.Add(fun e -> Application.Instance.Quit())
// create menu & get standard menu items (e.g. needed for OS X)
let menu = new MenuBar()
Application.Instance.CreateStandardMenu(menu.Items)
// add commands to the menu
let myMenu = menu.Items.GetSubmenu("&File")
myMenu.Items.Add(clickMe, 500)
myMenu.Items.AddSeparator(500)
myMenu.Items.Add(quitAction, 1000)
menu.Items.Trim()
form.Menu <- menu
// create toolbar
let toolbar = new ToolBar()
toolbar.Items.Add(clickMe)
form.ToolBar <- toolbar
form
let app = new Application()
let MainForm = MyEtoForm()
MainForm.Show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment