I am trying to use Graphics in C# 2022. I have included the following lines;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.ComponentModel;
using System.Resources;
using System.Drawing.Imaging;
using System.Drawing.Printing;
//using System.Drawing.Common;
using System.Text;
using System.Linq;
using System.Drawing.Drawing2D;
using System.Windows;
using CommonLibrary;
//using System.Imaging;
using System.Runtime.InteropServices;
namespace LazerPrintLibrary
but I get
Severity Code Description Project File Line Suppression State
Error CS1069 The type name 'Brush' could not be found in the namespace 'System.Drawing'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. LazerPrintLibrary E:\Projects22\LazerPrintLibrary\LazerPrintLibrary\LazerPrintClass.cs 305 Active
On looking further I also can not use Grids or buttons etc.
These all worked correctly in c# 2017.
Tuhin PaulPosted Mar 19, 2023, 6:52 AM
If you want to use WPF controls like grids and buttons, you should use WPF instead of Windows Forms, as it provides a more modern UI framework with support for XAML and vector graphics.
Tuhin PaulPosted Mar 19, 2023, 6:52 AM
Tuhin PaulPosted Mar 19, 2023, 6:50 AM
You're using .NET 6 or later, which introduces breaking changes in the System.Drawing namespace. In .NET 6, the System.Drawing.Common package is not included by default, and instead, you should use the cross-platform SkiaSharp library for graphics.
Abhijeet JadhavPosted Mar 18, 2023, 10:40 PM
The error message is indicating that the 'Brush' type cannot be found in the 'System.Drawing' namespace, and it suggests that the type has been forwarded to the 'System.Drawing.Common' assembly. The error also suggests that you consider adding a reference to that assembly.
To resolve this error, you need to add a reference to the 'System.Drawing.Common' assembly in your project. Here are the steps you can follow to add the reference:
In Visual Studio, right-click on your project in the Solution Explorer and select 'Add Reference' from the context menu.
In the 'Reference Manager' dialog box, select 'Assemblies' from the left-hand pane.
Search for 'System.Drawing.Common' in the search bar at the top of the dialog box.
Check the checkbox next to 'System.Drawing.Common' to select it.
Click the 'OK' button to add the reference.
After adding the reference, rebuild your project to ensure that the 'Brush' type is recognized by your code.