• 大小: 61KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-03
  • 语言: 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.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace DrawUtil
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();

            Setstyle(Controlstyles.DoubleBuffer true);
            Setstyle(Controlstyles.OptimizedDoubleBuffer true);
            Setstyle(Controlstyles.AllPaintingInWmPaint true);
            Setstyle(Controlstyles.UserPaint true);
            Setstyle(Controlstyles.SupportsTransparentBackColor true);   //模拟透明       
            Setstyle(Controlstyles.Selectable true);                     //接收焦点
            Setstyle(Controlstyles.AllPaintingInWmPaint true);           //忽略 WM_ERASEBKGND 窗口消息减少闪烁

            this.Updatestyles();

            this.Padding = new Padding(0 0 0 0);

            this.Margin = new Padding(0 0 0 0);

        }

        #region 变量

        LineClass line;

        bool drawkine = false;

        bool isDragTo = false;

        bool isStretchTo = false;

        Point dragFromPoint;

        Point dragToPoint;

        #endregion

        void m_PicDrawCtl_MouseDown(object sender MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                return;
            }

            try
            {
                try
                {
                    //新建图形
                    {
                        if (line == null)
                        {
                            line = new LineClass();

                            if (this.radioBtnLine.Checked)
                            {
                                line.Drawstyle = Drawstyle.Line;
                            }

                            if (this.radiobtnRect.Checked)
                            {
                                line.Drawstyle = Drawstyle.Rect;
                            }

                            line.Start = e.Location;

                            line.BackColor1 = this.m_PicDrawCtl.BackColor;

                            return;
                        }
                    }

                }
                catch { }
                try
                {
                    //拖拽图形
                    {
                        if (this.line.Contains(e.Location))
                        {
                            this.m_PicDrawCtl.Cursor = Cursors.SizeAll;

                            this.isDragTo = true;

                            this.dragFromPoint = e.Location;

                            return;
                        }
                    }

                }
                catch { }
                try
                { 
                    //继续绘制
                    {

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

     文件       5120  2017-09-30 10:10  DrawUtil\.vs\DrawUtil\v14\.suo

     文件        187  2017-09-29 13:48  DrawUtil\App.config

     文件      12800  2017-09-30 09:46  DrawUtil\bin\Debug\DrawUtil.exe

     文件        187  2017-09-29 13:48  DrawUtil\bin\Debug\DrawUtil.exe.config

     文件      30208  2017-09-30 09:46  DrawUtil\bin\Debug\DrawUtil.pdb

     文件      22984  2017-09-29 13:48  DrawUtil\bin\Debug\WindowsFormsApplication3.vshost.exe

     文件        187  2017-09-29 13:48  DrawUtil\bin\Debug\WindowsFormsApplication3.vshost.exe.config

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

     文件      13312  2017-09-30 10:09  DrawUtil\bin\Release\DrawUtil.exe

     文件        187  2017-09-29 13:48  DrawUtil\bin\Release\DrawUtil.exe.config

     文件      30208  2017-09-30 10:09  DrawUtil\bin\Release\DrawUtil.pdb

     文件      22696  2017-09-30 10:10  DrawUtil\bin\Release\DrawUtil.vshost.exe

     文件        187  2017-09-29 13:48  DrawUtil\bin\Release\DrawUtil.vshost.exe.config

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

     文件       3901  2017-09-29 14:18  DrawUtil\DrawUtil.csproj

     文件      11534  2017-09-30 10:09  DrawUtil\FormMain.cs

     文件       5062  2017-09-30 10:09  DrawUtil\FormMain.Designer.cs

     文件       5817  2017-09-30 10:09  DrawUtil\FormMain.resx

     文件        523  2017-09-29 14:18  DrawUtil\Program.cs

     文件       1354  2017-09-29 14:18  DrawUtil\Properties\AssemblyInfo.cs

     文件       2856  2017-09-29 14:18  DrawUtil\Properties\Resources.Designer.cs

     文件       5612  2017-09-29 13:48  DrawUtil\Properties\Resources.resx

     文件       1108  2017-09-29 14:18  DrawUtil\Properties\Settings.Designer.cs

     文件        249  2017-09-29 13:48  DrawUtil\Properties\Settings.settings

     目录          0  2017-09-30 09:03  DrawUtil\.vs\DrawUtil\v14

     目录          0  2017-09-30 08:54  DrawUtil\.vs\DrawUtil

     目录          0  2017-09-30 09:46  DrawUtil\bin\Debug

     目录          0  2017-09-30 10:09  DrawUtil\bin\Release

    ...D.H.         0  2017-09-30 08:54  DrawUtil\.vs

     目录          0  2017-09-29 17:56  DrawUtil\bin

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

评论

共有 条评论

相关资源