C#如何在显示器上画图(就是不画到C#的控件中)

解决方案 »

  1.   

    感觉是不是要用到DirectX编程啊?
      

  2.   

    如何在桌面上直接绘图Declare Auto Function GetDC Lib "user32" (ByVal hwnd As Integer) As IntPtr
    Dim p As System.IntPtr = GetDC(0) '取得屏幕
    Dim g As Graphics = Graphics.FromHdc(p)
    g.DrawRectangle(New Pen(Color.Black), 100, 100, 100, 100)
      

  3.   

    楼上是VB的我不想做引用要纯C#的
      

  4.   

    [DllImport("user32.dll")]
            private static extern int GetDC(int hwnd);        private void button1_Click(object sender, EventArgs e)
            {
              System.IntPtr p = (IntPtr)GetDC(0);// '取得屏幕
              Graphics g= Graphics.FromHdc(p);
              g.DrawRectangle(new Pen(Color.Black),new Rectangle (100,100,100,100));        }
      

  5.   

    C#里要用API才能在桌上上画图,不用API是不可以的.
      

  6.   

    可能用到的API有:
    [DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
    private static extern IntPtr IntGetDCEx(HandleRef hWnd, HandleRef hrgnClip, int flags);
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern IntPtr GetDesktopWindow();
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    private static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    private static extern bool RedrawWindow(HandleRef hwnd, ref RECT rcUpdate, HandleRef hrgnUpdate, int flags);
      

  7.   

    给你个在桌上画圆的代码吧:
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern IntPtr GetDesktopWindow();
    [DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
    private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);private void button1_Click(object sender, EventArgs e)
    {
    IntPtr desk = GetDesktopWindow();
    IntPtr deskDC = GetDCEx(desk, IntPtr.Zero, 0x403);
    Graphics g = Graphics.FromHdc(deskDC);
    g.FillEllipse(SystemBrushes.ControlText, 0, 0, 100, 100);
    }
      

  8.   

    一定要P/INVOKE  纯C#是不到的