(C#) GDI+简单绘图画直线

GDI+:Graphics Device InterfacePlus也就是图形设备接口,提供了各种丰富的图形图像处理功能;在C#.NET中,使用GDI+处理二维(2D)的图形和图像,使用DirectX处理三维(3D)的图形图像,图形图像处理用到的主要命名空间是System.Drawing:提供了对GDI+基本图形功能的访问,主要有Graphics类、Bitmap类、从Brush类继承的类、Font类、Icon类、Image类、Pen类、Color类等.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _10._2._1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //DrawOne(e.Graphics);
        }
        private void DrawOne(Graphics g)
        {
            //Graphics g = e.Graphics;
            g = this.CreateGraphics();
            Pen pen1 = new Pen(Color.Green, 5);
            Point[] points =
            {
                new Point(100,20),
                new Point(100,80),
                new Point(140,20),
                new Point(200,200)
            };
            g.DrawLines(pen1, points);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            DrawOne(g);
        }
    }
}


posted @ 2012-11-22 15:44  Finlay Liu  阅读(1005)  评论(0编辑  收藏  举报