2015-05-30 73 views
-5

我試圖實例化System.Drawing.Graphics對象,但由於某些原因,Visual Studio找不到該類。似乎這是一些.NET案例的情況,但不是.NET庫中的所有類。無法實例化一些.NET對象

我已經檢查了目標框架並試圖用命名空間實例化。此外,沒有選項可以在Visual Studio菜單中解決它,所以它看起來像Visual Studio甚至不知道該對象。

樣品的編號:

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); 
    } 
    } 
} 
+0

如果我必須打賭這是這個問題:http://stackoverflow.com/q/8553136/1348195 –

+1

'圖形'沒有公共構造函數。它有一些工廠方法你想做什麼? –

+0

@BenjaminGruenbaum沒有它沒有,我已經檢查,因爲我在問題中說。 – mstorm

回答

3

documentationSystem.Drawing.Graphics處於System.Drawing組件。

確保您參考System.Drawing

+0

我在7分鐘內接受它 – mstorm