• 大小: 100KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-10
  • 语言: 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;
using GraphExample.Shapes;
using GraphExample.Marks;

namespace GraphExample
{
    public partial class MainForm : Form
    {
        Canvas canvas = new Canvas();

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender EventArgs e)
        {
            canvas.Shapes.Add(new Box()
            {
                Rectangle = new Rectangle(100 100 400 500)
                UserData = new PowerStation()
            });
            canvas.Shapes.Add(new BoxWithoutOneAngle()
            {
                Rectangle = new Rectangle(150 150 200 66)
                UserData = new School()
            });

        }

        private void MainForm_Paint(object sender PaintEventArgs e)
        {
            Draw(e.Graphics);
        }

        public void Draw(Graphics g)
        {
            canvas.Draw(g);
        }

        Mark markonmousedown = null;
        Shape shapeonmousedown = null;
        Point pointonmousedown;
        Point pointInShapeonmousedown;

        private void MainForm_MouseDown(object sender MouseEventArgs e)
        {
            pointonmousedown = e.Location;

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
                markonmousedown = canvas.GetMark(e.X e.Y);
            if (markonmousedown != null)
                return;

            shapeonmousedown = canvas.GetShape(e.X e.Y);
            if (shapeonmousedown != null)
            {
                pointInShapeonmousedown = new Point(
                    e.Location.X -
                    shapeonmousedown.Rectangle.Location.X
                    e.Location.Y -
                    shapeonmousedown.Rectangle.Location.Y);
                shapeonmousedown.Selected = true;
            }
            else
                canvas.ClearSelection();

            this.Refresh();
        }

        private void MainForm_MouseMove(object sender MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (markonmousedown != null)
                {
                    markonmousedown.MoveTo(e.Location);
                    this.Refresh();
                    return;
                }
                else if (shapeonmousedown != null)
                {
                    shapeonmousedown.MoveTo(
                        new Point(e.X - pointInShapeonmousedown.X
                            e.Y - pointInShapeonmousedown.Y));
                    this.Refresh();
                    this.Cursor = Cursors.SizeAll;
                    return;
                }
            }

            Mark m = canvas.GetMark(e.X e.Y);
            if (m !

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2012-11-04 10:32  GraphExample2\
     文件         144  2012-11-04 11:01  GraphExample2\app.config
     目录           0  2012-11-04 10:32  GraphExample2\bin\
     目录           0  2012-11-04 10:32  GraphExample2\bin\Debug\
     文件       19456  2012-12-23 22:14  GraphExample2\bin\Debug\GraphExample.exe
     文件         144  2012-11-04 11:01  GraphExample2\bin\Debug\GraphExample.exe.config
     文件       83456  2012-12-23 22:14  GraphExample2\bin\Debug\GraphExample.pdb
     文件       11600  2012-12-28 15:49  GraphExample2\bin\Debug\GraphExample.vshost.exe
     文件         144  2012-11-04 11:01  GraphExample2\bin\Debug\GraphExample.vshost.exe.config
     文件         490  2012-06-06 02:06  GraphExample2\bin\Debug\GraphExample.vshost.exe.manifest
     目录           0  2012-10-19 15:55  GraphExample2\bin\Release\
     文件           1  2012-10-26 20:31  GraphExample2\ClassDiagram1.cd
     文件        4449  2012-11-04 11:01  GraphExample2\GraphExample.csproj
     文件         865  2012-10-12 17:18  GraphExample2\GraphExample.sln
     文件       39424  2012-12-28 15:50  GraphExample2\GraphExample.suo
     文件       46592  2012-11-02 17:24  GraphExample2\GraphExample.v11.suo
     文件        3140  2012-11-02 17:10  GraphExample2\MainForm.cs
     文件        1812  2012-10-19 17:18  GraphExample2\MainForm.Designer.cs
     文件        5817  2012-10-19 17:18  GraphExample2\MainForm.resx
     目录           0  2012-11-04 10:32  GraphExample2\Marks\
     文件        2369  2012-11-02 17:02  GraphExample2\Marks\Mark.cs
     文件         490  2012-11-02 17:06  GraphExample2\Marks\MarkCollection.cs
     文件         777  2012-11-02 17:02  GraphExample2\Marks\ShapeMark.cs
     文件         754  2012-11-02 17:02  GraphExample2\Marks\SizeMark.cs
     目录           0  2012-11-04 10:32  GraphExample2\obj\
     目录           0  2012-11-04 10:32  GraphExample2\obj\x86\
     目录           0  2012-12-23 22:14  GraphExample2\obj\x86\Debug\
     文件        4040  2012-11-13 23:33  GraphExample2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6108  2012-12-23 22:14  GraphExample2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         422  2012-10-26 16:27  GraphExample2\obj\x86\Debug\GenerateResource.read.1.tlog
     文件        1420  2012-10-26 16:27  GraphExample2\obj\x86\Debug\GenerateResource.write.1.tlog
............此处省略31个文件信息

评论

共有 条评论