Is it possible to make desktop GUI application in .NET Core?

后端 未结 15 1789
我在风中等你
我在风中等你 2020-12-12 11:02

I have been developing Windows Forms programs for few years. I am now looking into .NET Core (including ASP.NET Core MVC). I am searching for the new GUI desktop technology.

15条回答
  •  感情败类
    2020-12-12 11:11

    If you are using .NET Core 3.0 and above, do the following steps and you are good to go: (I'm going to use .NET Core CLI, but you can use Visual Studio too):

    1. md MyWinFormsApp optional step
    2. cd MyWinFormsApp optional step
    3. dotnet new sln -n MyWinFormsApp optional step, but it's a good idea
    4. dotnet new winforms -n MyWinFormsApp I'm sorry, this is not optional
    5. dotnet sln add MyWinFormsApp do this if you did step #3

    Okay, you can stop reading my answer and start adding code to the MyWinFormsApp project. But if you want to work with Form Designer, keep reading.

    1. Open up MyWinFormsApp.csproj file and change netcoreapp3.1 to net472;netcoreapp3.1 (if you are using netcoreapp3.0 don't worry. Change it to net472;netcoreapp3.0)
    2. Then add the following ItemGroup
      
        
          Form
        
        
          Form1.cs
        
      
    

    After doing these steps, this is what you should end up with:

    
    
      
        WinExe
        net472;netcoreapp3.1
        true
      
    
      
        
          Form
        
        
          Form1.cs
        
      
    
    
    
    1. Open up file Program.cs and add the following preprocessor-if
    #if NETCOREAPP3_1
        Application.SetHighDpiMode(HighDpiMode.SystemAware);
    #endif
    

    Now you can open the MyWinFormsApp project using Visual Studio 2019 (I think you can use Visual Studio 2017 too, but I'm not sure) and double click on Form1.cs and you should see this:

    Okay, open up Toolbox (Ctrl + W, X) and start adding controls to your application and make it pretty.

    You can read more about designer at Windows Forms .NET Core Designer.

提交回复
热议问题