• 大小: 121KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-22
  • 语言: C#
  • 标签: C#  制图  绘图  

资源简介

因项目需求,要实现简单的绘制矢量图形,因此自已写了几个自定义的Panel控件,有矩形,圆形,三角形,弧形,原则上可以实现各类形状的各类可视控件,并实现了拖拽和拉伸功能。代码在VS2010环境上生成。共享出来希望对有类似需求的童鞋有所帮助。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TestPingtu
{
    public class ExCirclePanel : Panel IPanelSet
    {
        private List lstAnchorPoint;
        private int AnchorPointRange;
        private MoveDirect curMoveDirect = MoveDirect.Default;
        private bool isEditing = false;
        private bool _IsEditable = false;

        /// 
        /// 控件当前是否处于可编辑状态
        /// 

        public bool IsEditable
        {
            get
            {
                return _IsEditable;
            }
            set
            {
                _IsEditable = value;
            }
        }

        private enum MoveDirect
        {
            Left = 0
            Right
            Top
            Bottom
            Default
        }

        private class AnchorPoint
        {
            public Rectangle AnchorRec;
            public MoveDirect AnchorDirect;
        }

        private Color _DefaultColor;
        /// 
        /// 默认背影色
        /// 

        public Color DefaultColor
        {
            get
            {
                return _DefaultColor;
            }
            set
            {
                this.BackColor = value;
                _DefaultColor = value;
            }
        }

        private Point mouse_offset;

        public ExCirclePanel()
        {
            this.Height = 100;
            this.Width = 100;
            AnchorPointRange = 5;
            InitialAnchorPoint();
        }

        public ExCirclePanel(Color defaultColor bool isEditable)
        {
            DefaultColor = defaultColor;
            IsEditable = isEditable;
            this.Height = 100;
            this.Width = 100;
            AnchorPointRange = 5;
            InitialAnchorPoint();
        }

        public void SetBackColor(Color backColor)
        {
            this.DefaultColor = backColor;
        }

        public void SetBoldShow(bool isShow)
        {
            if (isShow)
                this.Borderstyle = System.Windows.Forms.Borderstyle.FixedSingle;
            else
                this.Borderstyle = System.Windows.Forms.Borderstyle.None;
        }

        private void InitialAnchorPoint()
        {
            lstAnchorPoint = new List();

            AnchorPoint ap = new AnchorPoint()
            {
                AnchorRec = new Rectangle(0 this.Height / 2 - AnchorPointRange /2 AnchorPointRange AnchorPointRange)
                AnchorDirect = MoveDirect.Left
            };
            lstAnchorPoint.Add(ap);

            ap = new AnchorPoint()
            {
                AnchorRec = new Rectangle(this.Width - AnchorPointRange this.Height / 2 - AnchorPointRange / 2 AnchorPointRange AnchorPointRange)
                AnchorDirect

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

     文件      43008  2014-04-24 16:41  TestPingtu\TestPingtu\bin\Debug\TestPingtu.exe

     文件      73216  2014-04-24 16:41  TestPingtu\TestPingtu\bin\Debug\TestPingtu.pdb

     文件      11600  2014-04-24 16:43  TestPingtu\TestPingtu\bin\Debug\TestPingtu.vshost.exe

     文件        490  2010-03-17 22:39  TestPingtu\TestPingtu\bin\Debug\TestPingtu.vshost.exe.manifest

     文件       7951  2014-04-24 16:29  TestPingtu\TestPingtu\ExCirclePanel.cs

     文件      14975  2014-04-24 16:29  TestPingtu\TestPingtu\ExCurvedPanel.cs

     文件       9585  2014-04-24 16:29  TestPingtu\TestPingtu\ExRectanglePanel.cs

     文件      21134  2014-04-24 16:27  TestPingtu\TestPingtu\ExTrianglePanel.cs

     文件       6159  2014-04-24 16:41  TestPingtu\TestPingtu\Form1.cs

     文件      12393  2014-04-24 16:41  TestPingtu\TestPingtu\Form1.Designer.cs

     文件       6221  2014-04-24 16:41  TestPingtu\TestPingtu\Form1.resx

     文件       1120  2014-04-24 16:30  TestPingtu\TestPingtu\Form2.cs

     文件       5380  2014-04-24 16:17  TestPingtu\TestPingtu\Form2.Designer.cs

     文件      19417  2014-04-24 16:17  TestPingtu\TestPingtu\Form2.resx

     文件        277  2014-04-24 16:21  TestPingtu\TestPingtu\IPanelSet.cs

     文件       9134  2014-04-24 14:57  TestPingtu\TestPingtu\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6347  2014-04-24 16:41  TestPingtu\TestPingtu\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1783  2014-04-24 16:43  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.csproj.FileListAbsolute.txt

     文件       1033  2014-04-24 16:41  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.csproj.GenerateResource.Cache

     文件      43008  2014-04-24 16:41  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.exe

     文件        180  2014-04-24 16:41  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.Form1.resources

     文件      73216  2014-04-24 16:41  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.pdb

     文件        180  2014-04-24 16:29  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.Properties.Resources.resources

     文件       9228  2014-04-24 16:29  TestPingtu\TestPingtu\obj\x86\Debug\TestPingtu.SetForm.resources

     文件        502  2014-04-08 09:52  TestPingtu\TestPingtu\Program.cs

     文件       1432  2014-04-08 09:52  TestPingtu\TestPingtu\Properties\AssemblyInfo.cs

     文件       2849  2014-04-08 09:52  TestPingtu\TestPingtu\Properties\Resources.Designer.cs

     文件       5612  2014-04-08 09:52  TestPingtu\TestPingtu\Properties\Resources.resx

     文件       1096  2014-04-08 09:52  TestPingtu\TestPingtu\Properties\Settings.Designer.cs

     文件        249  2014-04-08 09:52  TestPingtu\TestPingtu\Properties\Settings.settings

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

评论

共有 条评论