zoukankan      html  css  js  c++  java
  • C#Graphics 画图类操作

    一、如何在桌面作图

    1.引用

    using System.Drawing;

    using System.Runtime.InteropServices;

    2.调用系统API

         [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);

     3.初始化Graphics 类

                IntPtr desk = GetDesktopWindow();
                IntPtr deskDC = GetDCEx(desk, IntPtr.Zero, 0x403);
                Graphics g = Graphics.FromHdc(deskDC);

    4.操作作图

                //Start point
                Point newPoint = new Point(0, 0);
                Pen p = new Pen(Color.Blue, 1);
                var Rectangle = new Rectangle(newPoint, new Size(500, 300));
                g.DrawRectangle(p, Rectangle);
                g.DrawString("测试", new Font("宋体", 50, FontStyle.Bold), Brushes.Red, new PointF(100, 100));
  • 相关阅读:
    基本STRUTS标签-学习笔记-Logic标签
    Static的使用
    模板template
    iostream与iostream.h的区别
    数据库连接池
    canvas基础
    javascript面试题集
    ES6新特性学习
    原型和原型链
    css为tbody或者li奇数偶数行样式
  • 原文地址:https://www.cnblogs.com/tangpeng97/p/12711105.html
Copyright © 2011-2022 走看看