基本信息
源码名称:C#入门级画板示例源码(画图板)
源码大小:3.59M
文件格式:.zip
开发语言:C#
更新时间:2018-08-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍


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;
using System.Drawing.Drawing2D;
using System.Drawing.Text;

namespace 画图板
{
    public partial class Form2 : Form
    {
        struct Line
        {

         public  Pen p;
          public int x2;
          public int x1;
          public int y1;
         public   int y2;

        }
        private List<Line> lHistory = new List<Line>();
        public Form2()
        {
            InitializeComponent();
        }
        Point p1, p2;
        bool b = true;
        Graphics g;
        Pen pen;
        Random ran = new Random();
        private void button1_Click(object sender, EventArgs e)
        {
            Graphics gp = this.CreateGraphics();
            gp.DrawLine(Pens .Red ,120,45,78,567); 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Graphics gh = this.CreateGraphics();
            gh.Clear(this.BackColor);
        }

        private void Form2_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                oldpoint.X = e.X;
                oldpoint.Y = e.Y;
            }

        }
        Point oldpoint = new Point();
        private void Form2_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {  Graphics g = CreateGraphics();
                if (blerase)
                {
                  

                    g.FillEllipse(Brushes.White, new Rectangle(e.X, e.Y, (int)NUEerase.Value, (int)NUEerase.Value));
                }
                else {

                    Pen psss = new Pen(Brushes.Red, (int)NUEerase.Value );
                g.DrawLine(psss, oldpoint, new Point(e.X, e.Y));
                oldpoint.X = e.X;
                oldpoint.Y = e.Y;
            }
        } }

        private void Form2_MouseUp(object sender, MouseEventArgs e)
        {
            //b = true;
        }

        private void button2_MouseDown(object sender, MouseEventArgs e)
        {
            b = false;
            p1.X = e.X;
            p1.Y = e.Y;

            
        }

        private void button2_MouseMove(object sender, MouseEventArgs e)
        {
          pen = new Pen(Color.Black, 2f);
            if (b) return;
            Graphics g = CreateGraphics();
            p2.X = e.X;
            p2.Y = e.Y;
            g.DrawLine(pen, p1, p2);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            p1.X = p2.X;

        }

        private void button2_MouseUp(object sender, MouseEventArgs e)
        {
            b = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                Graphics g = this.CreateGraphics();
                g.DrawImage(Image.FromFile(ofd.FileName), 50, 50);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            button3.BackColor = Color.Red;
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
           
            ColorDialog f = new ColorDialog();
            if (f.ShowDialog ()==DialogResult .OK )
            {  
              
   
                g.DrawLine(pen , p1, p2);
           
            
            }
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen p = new Pen(Brushes.Red, 20);
            g.DrawLine(p, 10, 10, 500, 455);
            Line l;
            l.p =p;
            l.x1 =10;
            l.x2 =10;
            l.y1 =500;
            l.y2=455;
            lHistory .Add (l);

        }

        private void Form2_Activated(object sender, EventArgs e)
        {
            if (lHistory .Count >0)
            {Line l=lHistory [lHistory .Count -1];
            Graphics g=this.CreateGraphics ();
                g.DrawLine (l.p ,l.x1,l.y1,l.x2 ,l.y2 );
            }
        }
        private bool blerase = false;//是否执行 橡皮擦功能flas不是true是
        private void button6_Click(object sender, EventArgs e)
        {
            blerase = true;

        }

        private void button7_Click(object sender, EventArgs e)
        {
            blerase = false;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
          

        }
    }
}