国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

winfrom-拖動鼠標繪制矩形

2019-11-11 02:41:07
字體:
來源:轉載
供稿:網友

using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;namespace WindowsFormsapplication2{    //http://bbs.csdn.net/topics/390567044    //http://heisetoufa.iteye.com/blog/380977    //http://blog.csdn.net/xuyongbeijing2008/article/details/17371311    public partial class Form2 : Form    {        bool bDrawStart = false;        Point pointStart = Point.Empty;        Point pointContinue = Point.Empty;        Dictionary<Point, Point> dicPoints;        public Form2()        {            InitializeComponent();            dicPoints = new Dictionary<Point, Point>();            DoubleBuffered = true;            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);            this.MouseDown += new MouseEventHandler(frmMain_MouseDown);            this.MouseMove += new MouseEventHandler(frmMain_MouseMove);            this.MouseUp += new MouseEventHandler(frmMain_MouseUp);            this.Paint += new PaintEventHandler(frmMain_Paint);        }        PRivate void frmMain_Paint(object sender, PaintEventArgs e)        {            Pen pen = new Pen(Color.Black, 1f);            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;                        if (bDrawStart)            {                //實時的畫矩形                int w = pointContinue.X - pointStart.X;                int h = pointContinue.Y - pointStart.Y;                Rectangle rect = new Rectangle(pointStart, new Size(w, h));                e.Graphics.DrawRectangle(pen, rect);            }            pen.Dispose();        }        void frmMain_MouseDown(object sender, MouseEventArgs e)        {            if (bDrawStart)            {                bDrawStart = false;            }            else            {                bDrawStart = true;                pointStart = e.Location;            }        }        void frmMain_MouseMove(object sender, MouseEventArgs e)        {            if (bDrawStart)            {                pointContinue = e.Location;                //Refresh();                Invalidate();            }        }        void frmMain_MouseUp(object sender, MouseEventArgs e)        {            if (bDrawStart)            {                dicPoints.Add(pointStart, pointContinue);            }            bDrawStart = false;        }        //...    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仁寿县| 南昌市| 宝鸡市| 孟津县| 舒兰市| 儋州市| 信宜市| 宁强县| 犍为县| 驻马店市| 虎林市| 景泰县| 仪陇县| 朝阳县| 忻城县| 昌黎县| 平江县| 临城县| 黔西| 满洲里市| 桐柏县| 双桥区| 鹿邑县| 苍溪县| 分宜县| 仙桃市| 镇江市| 西城区| 罗定市| 金溪县| 深泽县| 青神县| 静海县| 波密县| 青浦区| 喜德县| 买车| 高碑店市| 罗甸县| 隆安县| 象山县|