代码之家  ›  专栏  ›  技术社区  ›  Elias

c#只在屏幕的一部分绘制

c#
  •  0
  • Elias  · 技术社区  · 7 年前

       Console.WriteLine(Screen.PrimaryScreen.Bounds.Width);
       Console.WriteLine(Screen.PrimaryScreen.Bounds.Height);
    

    它记录:1620,1080这是我屏幕大小的一半。。。

    下面是我要绘制的代码:

     [DllImport("User32.dll")]
     public static extern IntPtr GetDC(IntPtr hwnd);
     [DllImport("User32.dll")]
     public static extern void ReleaseDC(IntPtr hwnd, IntPtr dc);
    
     static void Main(string[] args) {
        Console.WriteLine(Screen.PrimaryScreen.Bounds.Width);
        Console.WriteLine(Screen.PrimaryScreen.Bounds.Height);
    
        IntPtr desktopPtr = GetDC(IntPtr.Zero);
        Graphics g = Graphics.FromHdc(desktopPtr);
        SolidBrush b = new SolidBrush(Color.White);
        g.FillRectangle(b, new Rectangle(0, 0, 16000, 16000));
    }
    

    希望有人能帮我,埃利亚斯:)

    0 回复  |  直到 7 年前