I am trying to instantiate the System.Drawing.Graphics
object but for some reason Visual Studio can´t find the class. It seems that this is the case for some, but not all classes from the .NET Library.
I already checked the target framework and tried to instantiate with the Namespace. Also, there is no option for resolving it in the Visual Studio menu so it seems like Visual Studio doesnt even know the Object.
Sample code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Media;
namespace Notify.Classes
{
class NotificationDrawer
{
[DllImport("User32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("User32.dll")]
public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
IntPtr desktopPtr = GetDC(IntPtr.Zero);
Graphics g = Graphics.FromHdc(desktopPtr);
SolidBrush b = new SolidBrush(Color.White);
g.FillRectangle(b, new Rectangle(0, 0, 1920, 1080));
g.Dispose();
ReleaseDC(IntPtr.Zero, desktopPtr);
}
}
}