• 大小: 56KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: C#
  • 标签: C#  

资源简介

用C#制作的简易画图小程序,包括画笔,图形,颜色选择和线条宽度,橡皮,可用于关于鼠标事件的学习。

资源截图

代码片段和文件信息

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 DrawingBoard
{
    enum DrawTool
    { 
        Pen
        Line
        Ellipse
        Rectangle
        Rubber
    }

    public partial class Form1 : Form
    {
        private DrawTool tool;
        private Point starPt oldPtnewPt;
        private Pen pen=Pens.Red;
        private Graphics g;
        private Color forecolor;
        private int penWidth;
        private bool isDown = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load_1(object sender EventArgs e)
        {
            g = this.CreateGraphics();
        }

        private void toolColor_Click(object sender EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                forecolor = colorDialog1.Color;
                pen = new Pen(forecolor penWidth);
            }
        }

        private void toolPenWidth_SelectedIndexChanged(object sender EventArgs e)
        {
            toolPenWidth.Text = toolPenWidth.SelectedItem.ToString();
            penWidth = int.Parse(toolPenWidth.Text);
            pen = new Pen(forecolor penWidth);
        }

        private void toolPen_Click(object sender EventArgs e)
        {
            tool = DrawTool.Pen;
        }

        private void toolLine_Click(object sender EventArgs e)
        {
            tool = DrawTool.Line;
        }

        private void toolEllipse_Click(object sender EventArgs e)
        {
            tool = DrawTool.Ellipse;
        }

        private void toolRectangle_Click(object sender EventArgs e)
        {
            tool = DrawTool.Rectangle;
        }

        private void toolRubber_Click(object sender EventArgs e)
        {
            tool = DrawTool.Rubber;
        }

        private void Form1_MouseDown(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                starPt = new Point(e.X e.Y);
                oldPt = new Point(e.X e.Y);
                isDown = true;
            }
        }

        private void Form1_MouseUp(object sender MouseEventArgs e)
        {
            isDown = false;
            switch (tool)
            {
                case DrawTool.Line:
                    {
                        Point endpt = new Point(e.X e.Y);
                        g.DrawLine(pen starPt endpt);
                        break;
                    }
                case DrawTool.Ellipse:
                    {
                        Rectangle rect = new Rectangle(starPt.X starPt.Ye.X-starPt.Xe.Y-starPt.Y);
                        g.DrawEllipse(pen rect);
                        break;
                    }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      15872  2018-10-10 23:34  DrawingBoard\DrawingBoard\bin\Debug\DrawingBoard.exe

     文件      34304  2018-10-10 23:34  DrawingBoard\DrawingBoard\bin\Debug\DrawingBoard.pdb

     文件      11600  2018-10-10 23:42  DrawingBoard\DrawingBoard\bin\Debug\DrawingBoard.vshost.exe

     文件        490  2017-03-19 05:00  DrawingBoard\DrawingBoard\bin\Debug\DrawingBoard.vshost.exe.manifest

     文件        630  2018-10-10 19:30  DrawingBoard\DrawingBoard\Bitmap1.bmp

     文件        630  2018-10-10 19:30  DrawingBoard\DrawingBoard\Bitmap2.bmp

     文件        630  2018-10-10 19:30  DrawingBoard\DrawingBoard\Bitmap3.bmp

     文件        630  2018-10-10 19:30  DrawingBoard\DrawingBoard\Bitmap4.bmp

     文件       1270  2018-10-10 19:30  DrawingBoard\DrawingBoard\Bitmap5.bmp

     文件        630  2018-10-10 19:30  DrawingBoard\DrawingBoard\Bitmap6.bmp

     文件       3948  2018-10-10 19:30  DrawingBoard\DrawingBoard\DrawingBoard.csproj

     文件       3898  2018-10-10 23:34  DrawingBoard\DrawingBoard\Form1.cs

     文件       8515  2018-10-10 23:26  DrawingBoard\DrawingBoard\Form1.Designer.cs

     文件       9742  2018-10-10 23:26  DrawingBoard\DrawingBoard\Form1.resx

     文件       5420  2018-10-10 23:42  DrawingBoard\DrawingBoard\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6920  2018-10-10 23:34  DrawingBoard\DrawingBoard\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1290  2018-10-10 23:42  DrawingBoard\DrawingBoard\obj\x86\Debug\DrawingBoard.csproj.FileListAbsolute.txt

     文件        975  2018-10-10 23:26  DrawingBoard\DrawingBoard\obj\x86\Debug\DrawingBoard.csproj.GenerateResource.Cache

     文件      15872  2018-10-10 23:34  DrawingBoard\DrawingBoard\obj\x86\Debug\DrawingBoard.exe

     文件       2994  2018-10-10 23:26  DrawingBoard\DrawingBoard\obj\x86\Debug\DrawingBoard.Form1.resources

     文件      34304  2018-10-10 23:34  DrawingBoard\DrawingBoard\obj\x86\Debug\DrawingBoard.pdb

     文件        180  2018-10-10 20:47  DrawingBoard\DrawingBoard\obj\x86\Debug\DrawingBoard.Properties.Resources.resources

     文件        493  2018-10-10 19:09  DrawingBoard\DrawingBoard\Program.cs

     文件       1374  2018-10-10 19:09  DrawingBoard\DrawingBoard\Properties\AssemblyInfo.cs

     文件       2876  2018-10-10 19:09  DrawingBoard\DrawingBoard\Properties\Resources.Designer.cs

     文件       5612  2018-10-10 19:09  DrawingBoard\DrawingBoard\Properties\Resources.resx

     文件       1099  2018-10-10 19:09  DrawingBoard\DrawingBoard\Properties\Settings.Designer.cs

     文件        249  2018-10-10 19:09  DrawingBoard\DrawingBoard\Properties\Settings.settings

     文件        878  2018-10-10 19:09  DrawingBoard\DrawingBoard.sln

    ..A..H.     34304  2018-10-10 23:42  DrawingBoard\DrawingBoard.suo

............此处省略12个文件信息

评论

共有 条评论