是否可以在不使用 Visual Studio 的情况下在 F# 中创建一个不会打开 CMD 窗口的 Winforms 应用程序?
我知道我可以简单地创建一个 VS 项目并将“输出类型”设置为“Windows 应用程序”。但我真的很喜欢简单地启动任何类型的文本编辑器并开始破解的方法。
是否可以在不使用 Visual Studio 的情况下在 F# 中创建一个不会打开 CMD 窗口的 Winforms 应用程序?
我知道我可以简单地创建一个 VS 项目并将“输出类型”设置为“Windows 应用程序”。但我真的很喜欢简单地启动任何类型的文本编辑器并开始破解的方法。
只需在编译器选项
fsc source.fsx --target:WinExe 中使用 --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
(确保 fsi.exe 在您的 PATH 中)