zoukankan      html  css  js  c++  java
  • Graphics Class

    System.Drawing 封装一个 GDI+ 绘图图面。 此类不能被继承。

    https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.graphics?view=netframework-4.7.2#%E6%96%B9%E6%B3%95

     1 using System;
     2 using System.Drawing;
     3 using System.Collections;
     4 using System.ComponentModel;
     5 using System.Windows.Forms;
     6 using System.Data;
     7   
     8 public class Form1 : Form
     9 {
    10     public Form1()
    11     {
    12         this.AutoScaleBaseSize = new Size(6, 14);
    13         this.ClientSize = new Size(400, 400);
    14         this.Paint += new PaintEventHandler(this.Form1_Paint);
    15         this.Click += new EventHandler( this.Draw );
    16     }
    17     static void Main() 
    18     {
    19         Application.Run(new Form1());
    20     }
    21     
    22     //Paint事件调用
    23     private void Form1_Paint(object sender, PaintEventArgs e)
    24     {
    25         Graphics g = e.Graphics;//传进来的对象不需要释放
    26         
    27         Brush brush = new SolidBrush(Color.Green);
    28         Font font = new Font("宋体", 25);
    29                 
    30         g.DrawString("绘制", font, brush, 250, 20);        
    31     }
    32     
    33     //在已存在的窗体上创建Graphics对象
    34     //窗体控件,Click事件
    35     private void Draw(object sender, EventArgs e)
    36     {   
    37         Graphics g = this.CreateGraphics();
    38         
    39         Pen pen = new Pen(Color.Red, 2);
    40         Brush brush = new SolidBrush(Color.Blue);
    41         Font font = new Font("宋体", 25);
    42         Rectangle rect = new Rectangle(20, 120, 100, 160);
    43         
    44         g.DrawLine(pen, 20, 100, 100, 100);
    45         g.DrawRectangle(pen, rect);
    46         g.DrawString("GDI+图形编程", font, brush, 20, 20);
    47         
    48         brush.Dispose(); font.Dispose(); pen.Dispose();//释放对象
    49         g.Dispose();
    50     }   
    51 }
    Graphics类方法的使用
  • 相关阅读:
    1.Apache与Tomcat
    jeeplus 多选框
    GIT 回滚
    jsp 中data 转换 字符串
    Pattern和Matcher中表达式
    web.xml 详细介绍
    $.ajax()方法详解
    My 2016
    如何做好一个保安队长。
    集合之WeakHashMap
  • 原文地址:https://www.cnblogs.com/GoldenEllipsis/p/10675232.html
Copyright © 2011-2022 走看看