是否可以在F#中創建一個Winforms應用程序,其中沒有使用Visual Studio打開CMD窗口?如何在沒有Visual Studio的情況下創建一個f#windows應用程序(無cmd窗口)
我知道我可以簡單地創建一個VS項目並將'輸出類型'設置爲'Windows應用程序'。但我真的很喜歡簡單地啓動任何一種文本編輯器並開始黑客入侵的方法。
是否可以在F#中創建一個Winforms應用程序,其中沒有使用Visual Studio打開CMD窗口?如何在沒有Visual Studio的情況下創建一個f#windows應用程序(無cmd窗口)
我知道我可以簡單地創建一個VS項目並將'輸出類型'設置爲'Windows應用程序'。但我真的很喜歡簡單地啓動任何一種文本編輯器並開始黑客入侵的方法。
只需使用--target:在編譯器選項WinExe
FSC source.fsx --target:WinExe
打開任何編輯結束寫的東西是這樣的:
open System
open System.Drawing
open System.Windows.Forms
// Create form, button and add button to form
let form = new Form(Text = "Hello world!")
let btn = new Button(Text = "Click here")
form.Controls.Add(btn)
// Register event handler for button click event
btn.Click.Add(fun _ ->
// Generate random color and set it as background
let rnd = new Random()
let r, g, b = rnd.Next(256), rnd.Next(256), rnd.Next(256)
form.BackColor <- Color.FromArgb(r, g, b))
// Show the form (in F# Interactive)
form.Show()
// Run the application (in compiled application)
Application.Run(form)
將它保存爲擴展.fsx
(如「Form.fsx
‘) 運行’fsi Form.fsx
」命令行文件。 (請確保您的PATH fsi.exe)
感謝您的迴應。也許我在我的問題上含糊不清。我的意圖是在哪裏創建一個exe文件。@sam的回答正是我所期待的。 – grafoo
最簡單的辦法是遵循一些Linux的說明,只是如何改變路徑指向fsharpc.exe –