提问人:Schrödingers Capybara 提问时间:3/14/2023 最后编辑:Neil BarnwellSchrödingers Capybara 更新时间:3/14/2023 访问量:185
Replit.com:在 c 中使用 System.Windows.Forms 命名空间时出现问题#
Replit.com: Problem using System.Windows.Forms namespace in c#
问:
我正在尝试在 https://replit.com/ 上学习 c#,并在网上找到了用于将图形绘制到屏幕上的代码。
代码曾经有效,但现在不再有效了。现在,每当我运行以下内容时:
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Windows.Forms;
using System.Drawing;
public class Form1 : Form
{
//Code Here\\
}
我收到错误:
>> dotnet run
/home/runner/Rope-Simulation/main.cs(4,22): error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) [/home/runner/Rope-Simulation/main.csproj]
我尝试浏览包括.NET主页在内的几个网站,但没有任何效果。
另外,知道我没有下载 .NET,但我在 replit.com 中使用了 c# .NET 版本,这可能会有所帮助。
另外,请不要给出复杂的答案,我是 c# 的初学者,仍在学习这些术语。
答:
这里的其他答案指出,Replit 不支持 Windows 窗体,因为它在 Linux 上运行。
因此,Windows 窗体已进入 .NET Core,但除了基于 Windows 的 .net 运行时之外,其他任何内容都不支持它。
我想说的是在 Windows 计算机上使用 Visual Studio,并查看一个现代 Windows 窗体示例。让它工作(甚至只是 ,然后将您要尝试的代码移植到该工作示例中,而不是批量复制它。File->New Project->Windows Forms (.NET Core)
它们还包含有关移植 .NET Framework 项目的信息,这些信息可能会告诉您要更改的具体内容: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/migration/?view=netdesktop-7.0
当然,您的替代方法是实际创建一个 .NET Framework(例如 4.8)项目,并将代码复制到其中。作为一种学习练习,这很好,但绝对不要构建实际使用的应用程序。
评论
不能在 Replit 上创建 Windows 窗体应用程序。Windows 窗体需要 Windows 操作系统。Replit运行在Linux上。
请参阅 Replit 用户论坛。
评论