【问题标题】:how to create a f# windows application (no cmd window) without visual studio如何在没有 Visual Studio 的情况下创建 f# windows 应用程序(无 cmd 窗口)
【发布时间】:2016-04-09 22:54:46
【问题描述】:

是否可以在不使用 Visual Studio 的情况下在 F# 中创建一个不会打开 CMD 窗口的 Winforms 应用程序?

我知道我可以简单地创建一个 VS 项目并将“输出类型”设置为“Windows 应用程序”。但我真的很喜欢简单地启动任何类型的文本编辑器并开始破解的方法。

【问题讨论】:

  • 最简单的方法是遵循一些 linux 指令,然后弄清楚如何更改指向 fsharpc.exe 的路径

标签: winforms visual-studio f# text-editor visual-studio-project


【解决方案1】:

只需在编译器选项中使用 --target:WinExe
fsc source.fsx --target:WinExe

【讨论】:

    【解决方案2】:

    打开任何编辑器结束写这样的东西:

    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 中)

    【讨论】:

    • 感谢您的回复。也许我的问题含糊不清。我打算在哪里创建一个exe文件。 @sam 的答案正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 2010-09-07
    • 2010-12-16
    • 2015-12-09
    • 2015-11-04
    • 2010-10-23
    • 1970-01-01
    相关资源
    最近更新 更多