I have an f# script using Windows Forms and I want it to run without showing console window (fsi.exe). Is it possible and how? Below is a script example.
#r "mscorlib.dll"
#r "System.dll"
open System.IO
open System.Windows.Forms
let DoUsefulThing() = ()
let form = new Form()
let button = new Button(Text = "Do useful thing")
button.Click.AddHandler(fun _ _ -> DoUsefulThing())
form.Controls.Add(button)
form.ShowDialog()
as one option you can PInvoke and hide console window
#r "mscorlib.dll"
#r "System.dll"
open System.IO
open System.Windows.Forms
module FSI =
[<System.Runtime.InteropServices.DllImport("user32.dll")>]
extern bool ShowWindow(nativeint hWnd, int flags)
let HideConsole() =
let proc = System.Diagnostics.Process.GetCurrentProcess()
ShowWindow(proc.MainWindowHandle, 0)
FSI.HideConsole()
let DoUsefulThing() = ()
let form = new Form()
let button = new Button(Text = "Do useful thing")
button.Click.AddHandler(fun _ _ -> DoUsefulThing())
form.Controls.Add(button)
form.ShowDialog()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With