Trying updating FSharpExample to net5.0 (#1479)

* Trying updating to net5.0

* Fixes error. Thanks to @En3Tho

* Changed to the correct event.

* Cleaning on shutdown.
This commit is contained in:
BDisp
2021-10-26 07:52:16 +01:00
committed by GitHub
parent 264c4cc163
commit f0a655a1c8
2 changed files with 23 additions and 17 deletions

View File

@@ -235,11 +235,11 @@ let ShowHex (top: Toplevel) =
type MenuItemDetails () =
inherit MenuItem ()
new (title: ustring, help: string, action: Action) as this =
new (title: ustring, help: ustring, action: Action) as this =
MenuItemDetails ()
then
this.Title <- title
this.Help <- ustr help
this.Help <- help
this.Action <- action
static member Instance (mi: MenuItem) =
@@ -362,10 +362,10 @@ let Main () =
Width = Dim.Fill () - Dim.op_Implicit margin,
Height = Dim.Fill () - Dim.op_Implicit margin)
let menuItems =
[|MenuItemDetails (ustr "F_ind", "", Unchecked.defaultof<_>);
MenuItemDetails (ustr "_Replace", "", Unchecked.defaultof<_>);
MenuItemDetails (ustr "_Item1", "", Unchecked.defaultof<_>);
MenuItemDetails (ustr "_Also From Sub Menu", "", Unchecked.defaultof<_>)|]
[|MenuItemDetails (ustr "F_ind",ustr "", Unchecked.defaultof<_>);
MenuItemDetails (ustr "_Replace", ustr "", Unchecked.defaultof<_>);
MenuItemDetails (ustr "_Item1", ustr "", Unchecked.defaultof<_>);
MenuItemDetails (ustr "_Also From Sub Menu", ustr "", Unchecked.defaultof<_>)|]
menuItems.[0].Action <- fun _ -> ShowMenuItem (menuItems.[0])
menuItems.[1].Action <- fun _ -> ShowMenuItem (menuItems.[1])
menuItems.[2].Action <- fun _ -> ShowMenuItem (menuItems.[2])
@@ -381,25 +381,29 @@ let Main () =
MenuItem (ustr "_Disabled", ustring.Empty, (fun () -> ()), (fun () -> false))
Unchecked.defaultof<_>
MenuItem (ustr "_Quit", ustring.Empty, (fun () -> if Quit() then top.Running <- false)) |])
MenuBarItem (ustr "_Edit",
MenuBarItem (ustr "_Edit",
[| MenuItem (ustr "_Copy", ustring.Empty, fun () -> Copy())
MenuItem (ustr "C_ut", ustring.Empty, fun () -> Cut())
MenuItem (ustr "_Paste", ustring.Empty, fun () -> Paste())
MenuBarItem (ustr "_Find and Replace",
[| menuItems.[0]
menuItems.[1] |])
menuItems.[3] |])
[| menuItems.[0] :> MenuItem
menuItems.[1] :> MenuItem |]) :> MenuItem
menuItems.[3] :> MenuItem
|])
MenuBarItem (ustr "_List Demos",
[| MenuItem (ustr "Select _Multiple Items", ustring.Empty, (fun () -> ListSelectionDemo true))
MenuItem (ustr "Select _Single Item", ustring.Empty, (fun () -> ListSelectionDemo false)) |])
MenuBarItem(ustr "A_ssorted",
MenuBarItem (ustr "A_ssorted",
[| MenuItem (ustr "_Show text alignments", ustring.Empty, (fun () -> ShowTextAlignments()))
MenuItem (ustr "_OnKeyDown/Press/Up", ustring.Empty, (fun () -> OnKeyDownPressUpDemo())) |])
MenuBarItem(ustr "_Test Menu and SubMenus",
MenuBarItem (ustr "_Test Menu and SubMenus",
[| MenuBarItem (ustr "SubMenu1Item_1",
[| MenuBarItem (ustr "SubMenu2Item_1",
[| MenuBarItem (ustr "SubMenu3Item_1",
[| menuItems.[2] |]) |]) |]) |])
[| menuItems.[2] :> MenuItem |]) :> MenuItem
|]) :> MenuItem
|]) :> MenuItem
|])
MenuBarItem (ustr "_About...", ustr "Demonstrates top-level menu item", (fun () -> MessageBox.ErrorQuery (50, 7, ustr "Error", ustr "This is a demo app for gui.cs", ustr "Ok") |> ignore)) |])
menuKeysStyle <- new CheckBox (3, 25, ustr "UseKeysUpDownAsKeysLeftRight", true)
menuKeysStyle.add_Toggled (Action<bool> (MenuKeysStyleToggled))
@@ -431,15 +435,17 @@ let Main () =
win.Add bottom
let bottom2 = new Label (ustr "This should go on the bottom of another top-level!")
top.Add bottom2
Application.Loaded <- Action<Application.ResizedEventArgs> (
fun _ ->
top.add_LayoutComplete (Action<View.LayoutEventArgs>
(fun e ->
bottom.X <- win.X
bottom.Y <- Pos.Bottom win - Pos.Top win - Pos.At margin
bottom2.X <- Pos.Left win
bottom2.Y <- Pos.Bottom win)
)
top.Add win
top.Add (menu, statusBar)
Application.Run ()
Application.Shutdown ();
module Demo =
[<EntryPoint>]