C#绘图

来源:互联网 发布:cocos2d x游戏源码 编辑:程序博客网 时间:2024/05/16 08:25
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 WindowsFormsApplication1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        Pen pen = null; //定义一个画笔pen        Graphics g = null; //定义一个画布        Point p0, p1; //定义两个坐标点        private void Form1_Load(object sender, EventArgs e)        {            pen = new Pen(Color.Black);            g = this.CreateGraphics();        }        private void button1_Click(object sender, EventArgs e)        {            colorDialog1.ShowDialog();                        pen.Color = colorDialog1.Color;        }        private void Form1_MouseDown(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)                p1 = e.Location;        }        private void Form1_MouseMove(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)            {                p0 = p1;                p1 = e.Location;                g.DrawLine(pen, p0, p1);//实现画线            }        }    }}

0 0
原创粉丝点击