在VS中创建窗体

(1)CDI+清除绘画面

在窗体中写入代码:

protected override void OnPaint(PaintEventArgs e){

  Graphics g=e.Graphics;

  g.Clear(Color.Pink);

  g.Dispose();

}

(2)CGD+绘制多边形

protected override void OnPaint(PaintEventArgs e){

  Graphics g=e.Graphics;

  Point[] points=new Point[]{

          new Point(200,200),

          new Point(230,230),

          new Point(260,300),

          new Point(300,350)

};

  g.DrawPolygon(new Pen(Color.Red),point);

  g.Dispose();

}

(3)GDI+填充颜色

protected override void OnPaint(PaintEventArgs e){

  //简单填充颜色

  Graphics g=e.Graphics;

  g.FillRectangle(Brushes.Red,new Rectangle(20,20,100,200));

  //渐变颜色填充

  Brush brush=new LinearGradientBrush(new Point(10,10),new Point(10,10),Color.Yellow,Color.White);

   g.FillRectangle(brush,new Rectangle(20,20,100,170));  

  g.Dispose();

}

(4)GDI+绘画路径

protected override void OnPaint(PaintEventArgs e){

   Graphics g = e.Graphics;
            Point[] points = new Point[]{
                 new Point(100,100),
                 new Point(100,150),
               new Point(150,200),
              new Point(50,200),
            };

  GraphicsPath path = new GraphicsPath(

      points,new byte[]{

          (byte)PathPointType.Start,

          (byte)PathPointType.Line,

          (byte)PathPointType.Line,

          (byte)PathPointType.Line 

      );

}

  g.DrawPath(new Pen(Color.Red),path);

  g.Dispose();

}

(4)GDI+绘制字符串

protected override void OnPaint(PaintEventArgs e){

  Graphics g = e.Graphics;

  //普通绘制字符串

  Font font1=new System.Drawing.Font("宋体",30);

  g.DrawingString("ABCD",font1,Brushes.Red,new PointF(30,30));

  //带格式的字符串

         Font font2 = new System.Drawing.Font("宋体", 30);
            RectangleF rect = new RectangleF(100,100,100,200);
            g.DrawRectangle(new Pen(Color.Red),new Rectangle(100,100,100,200));
            //字符串格式对象
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;//在矩形中居中
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString("abcd",font2,Brushes.Red,rect,sf);
            g.Dispose();

}

(5)GDI+纹理绘画图片

protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Image image = Image.FromFile("图片路径");
            //纹理画笔
            Brush brush = new TextureBrush(image);//刷出来的位置都有image的存在
            g.DrawRectangle(new Pen(Color.Pink),40,40,300,300);
            g.FillRectangle(brush,new Rectangle(40,40,300,300));
            g.Dispose();

}

最新文章

  1. win2008 64位 + oracle11G 64位 IIS7.5 配置WEBSERVICE
  2. C#中的强类型说明
  3. js 鼠标双击滚动单击停止
  4. Android Audio Focus的应用(requestAudioFocus)
  5. EF+SQLSERVER控制并发下抢红包减余额(改进)
  6. OPENCV3——从入门到出门
  7. CSS的常见问题
  8. C#日志文件
  9. C++异常处理 - 栈解旋,异常接口声明,异常类型和异常变量的生命周期
  10. GlusterFS群集存储项目
  11. 超级账本Hyperledge的关键部件说明
  12. tabel 选中行变色和取当前选中行值等问题
  13. Jmeter(二十一)_脚本参数化与内存溢出的解决方案
  14. C#窗体随机四则运算 (第四次作业)
  15. 【matlab】使用VideoReader提取视频的每一帧,不能用aviread函数~
  16. 北京Uber优步司机奖励政策(2月25日)
  17. LeetCode OJ:Compare Version Numbers(比较版本字符串)
  18. Gym - 101334E 多叉树遍历
  19. 微信小程序,设置所有标签样式
  20. Django之cookie 和 session

热门文章

  1. 网站定时任务IIS配置
  2. Spring属性占位符 PropertyPlaceholderConfigurer
  3. oc自定义不定参数函数
  4. 使用node.js 文档里的方法写一个web服务器
  5. 使用Squid搭建HTTPS代理服务器
  6. easyui data-options的使用
  7. 如何创建Windows定时任务
  8. Openstack(Kilo)安装系列之环境准备(二)
  9. Shader 优化笔记
  10. shell bash使用,包括判断文件或文件夹是否存在举例