How can I enable a WinForms or WPF project in F#?

前端 未结 4 1763
盖世英雄少女心
盖世英雄少女心 2021-02-05 05:15

I have the very latest version of Visual Studio 2017 installed. I selected F# language support and F# desktop support. After restarting and going to File -> New Project I was ex

4条回答
  •  温柔的废话
    2021-02-05 05:54

    You can create both WPF and WinForms applications in F#. There is no template for it, but it is certainly possible and many people do this. To create a simple WinForms application, you can do the following:

    • Create a new console application. Go to project properties and change "Output type" in the "Application" page from "Console application" to "Windows Application"

    • Right click on "References" in the project and add reference to "System.Windows.Forms" and "System.Drawing" (in the "Framework" tab).

    • Replace the code in Program.fs with the following:

      open System.Windows.Forms
      
      let f = new Form()
      f.Controls.Add(new Label(Text="Hello world!"))
      Application.Run(f)
      

    For anything bigger, you will probably want to use a nice F# GUI library such as the FsXaml project mentioned by Isaac or Gjallarhorn, but the basic first steps will be the same - create a console project, make it a windows project and then add relevant references to GUI frameworks.

提交回复
热议问题