Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# System.Drawing Reference issue

I'm a total noob when it comes to C#, C++ (C anything) and visual studio.

I'm trying to draw a table over a chart using

public override void OnPaintChart(PaintChartEventArgs args)
        {
            Graphics gr = args.Graphics;

            Font font = new Font("Arial", 10);
    
            for (int i = 0; i < KeyLevel.Length; i++)
                gr.DrawString(KeyLevel[i].ToString(), font, Brushes.LightGray, 20, 23 * i + 30);
        }

but i'm getting the following error: "The type 'Graphics' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc6......."

If I right click my project and go to Add > References, the only available system.drawing is showing as version 4.0.0.0.

I've updated visual studio and updated .net.

I've stated/referenced?? (dont know terminology)

using System;
using System.Drawing;

at the beginning of my script.

How do i get version 6.0.0.0?

I'm really stuck with this.

Thanks in advance.

like image 356
ABB1987 Avatar asked Feb 10 '26 23:02

ABB1987


1 Answers

Solution if anybody runs into same problem.

Update to Visual Studio 2022.

Update .net

In visual studio, right click project > Manage NuGet Packages

Search drawing and install package.

Swear at Microsoft for making life hard.

Done.

like image 66
ABB1987 Avatar answered Feb 13 '26 16:02

ABB1987