C
C#7mo ago
Evade

The type or namespace name 'Screen' does not exist in the namespace 'System.Windows.Forms'

no clue why code:
using System;
using System.Drawing;
using System.Windows.Forms;

class Program
{
static void Main()
{
// Define the RGB color to check
Color colorToCheck = Color.FromArgb(255, 255, 100);

// Capture the screen
using (Bitmap screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
{
using (Graphics g = Graphics.FromImage(screenBitmap))
{
g.CopyFromScreen(0, 0, 0, 0, screenBitmap.Size);
}

// Check if the color is present on the screen
bool colorFound = false;
for (int x = 0; x < screenBitmap.Width; x++)
{
for (int y = 0; y < screenBitmap.Height; y++)
{
if (screenBitmap.GetPixel(x, y) == colorToCheck)
{
colorFound = true;
break;
}
}
if (colorFound)
break;
}

// Print the result
if (colorFound)
{
Console.WriteLine("The RGB color (255, 255, 100) is displayed on the screen.");
}
else
{
Console.WriteLine("The RGB color (255, 255, 100) is not displayed on the screen.");
}
}
}
}
using System;
using System.Drawing;
using System.Windows.Forms;

class Program
{
static void Main()
{
// Define the RGB color to check
Color colorToCheck = Color.FromArgb(255, 255, 100);

// Capture the screen
using (Bitmap screenBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
{
using (Graphics g = Graphics.FromImage(screenBitmap))
{
g.CopyFromScreen(0, 0, 0, 0, screenBitmap.Size);
}

// Check if the color is present on the screen
bool colorFound = false;
for (int x = 0; x < screenBitmap.Width; x++)
{
for (int y = 0; y < screenBitmap.Height; y++)
{
if (screenBitmap.GetPixel(x, y) == colorToCheck)
{
colorFound = true;
break;
}
}
if (colorFound)
break;
}

// Print the result
if (colorFound)
{
Console.WriteLine("The RGB color (255, 255, 100) is displayed on the screen.");
}
else
{
Console.WriteLine("The RGB color (255, 255, 100) is not displayed on the screen.");
}
}
}
}
11 Replies
reflectronic
reflectronic7mo ago
i think you need to enable Windows Forms in your project can you show your project file
Evade
EvadeOP7mo ago
how can I do that in jetbrains rider?
Evade
EvadeOP7mo ago
No description
reflectronic
reflectronic7mo ago
yes, can you right click on it and press edit project file
Evade
EvadeOP7mo ago
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
</ItemGroup>

</Project>
it opens up this
reflectronic
reflectronic7mo ago
change net8.0 to net8.0-windows then, bellow <Nullable>enable</Nullable>, add <UseWindowsForms>true</UseWindowsForms>
Evade
EvadeOP7mo ago
great! tysm I moved from knowing a bit of python and javascript straight up to csharp so I'm getting used to things
Buddy
Buddy7mo ago
What are you trying to make??
Evade
EvadeOP7mo ago
color detection program
Buddy
Buddy7mo ago
For? o.o
Evade
EvadeOP7mo ago
fun and practice I started learning c# yesterday and I made that (with a little help of gpt, nothing crazy though :p)
Want results from more Discord servers?
Add your server