在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C#入门级画板示例源码(画图板)

C#入门级画板示例源码(画图板)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:3.59M
  • 下载次数:85
  • 浏览次数:1881
  • 发布时间:2018-08-25
  • 实例类别:C#语言基础
  • 发 布 人:201208090039
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 绘图

实例介绍

【实例简介】

【实例截图】

from clipboard


from clipboard

【核心代码】

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)
        {
          

        }
    }
}

标签: 绘图

实例下载地址

C#入门级画板示例源码(画图板)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 蒲公英3 发表于: 2019-10-17 14:52 13
资源无法下载

支持(0) 盖楼(回复)

第 2 楼 蒲公英3 发表于: 2019-10-17 14:52 13
资源无法下载

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有2条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警