1

I am trying to learn c# on https://replit.com/, and found code online for drawing graphics to the screen.

The code used to work, but it doesn't anymore. Now anytime I run the following:

using System;
using System.Collections.Generic;
using System.Numerics;
using System.Windows.Forms;
using System.Drawing;

public class Form1 : Form
{
//Code Here\\
}

I get the error:

>> 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]

I have tried looking through several sites including the .NET homepage, but nothing is working.

Also, It may help you to know that I haven't downloaded .NET, but am using the c# .NET version in replit.com.

Also, please don't give big complicated answers, I am a beginner in c# and am still learning the terms.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
  • If it worked before and now it doesn't, there must have been some sort of change. So, if you can, revert to the last version you know worked, test it. If that now also doesn't work, it may be due to some change in your development environment rather than your code. – Fildor Mar 13 '23 at 16:18
  • If it does work again, track your steps until you get to the exact point it breaks again. Then you are really close to the culprit. – Fildor Mar 13 '23 at 16:20
  • Damn, I didn't even notice the replit tag. I wish that was in the title of the question. lol – Neil Barnwell Mar 13 '23 at 16:38

2 Answers2

1

Other answers here point out that Replit doesn't support Windows Forms, because it runs on Linux.

So Windows Forms has made it to .NET Core, but it'll be unsupported on anything other than a Windows-based .net runtime.

I'd say to use Visual Studio on a Windows machine, and look at a modern Windows Forms example. Get that working (or even just File->New Project->Windows Forms (.NET Core), then port just the code you're looking to try into that working example, rather than copying it wholesale.

Here's an example: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/get-started/create-app-visual-studio?view=netdesktop-7.0

They also have information on porting .NET Framework projects over, which may tell you the specific things to change: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/migration/?view=netdesktop-7.0

Of course your alternative is to actually create a .NET Framework (e.g. 4.8) project and copy your code into that, instead. As a learning exercise this would be fine, but definitely don't build apps for actual use on that.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
  • Is there any other way to draw graphics? I cant use a virtual machine or anything, because I am on chromeOS. – Schrödingers Capybara Mar 13 '23 at 17:00
  • It depends what you need. If a browser would work, you can do anything with an html Canvas and some JavaScript. That wouldn't be dissimilar to GDI+ in spirit, such is what you were considering. – Neil Barnwell Mar 14 '23 at 19:08
1

You cannot create a Windows Forms application on Replit. Windows Forms requires a Windows operating system. Replit runs on Linux.

See on Replit user forum.

NineBerry
  • 26,306
  • 3
  • 62
  • 93