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

首頁 > 學院 > 開發(fā)設計 > 正文

winfrom-拖動鼠標繪制矩形

2019-11-11 04:06:06
字體:
來源:轉載
供稿:網(wǎng)友

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;        }        //...    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 嵊泗县| 澄城县| 永年县| 娄烦县| 封开县| 柏乡县| 东明县| 平顶山市| 巫溪县| 巴南区| 中阳县| 封开县| 榕江县| 通州区| 新巴尔虎右旗| 吉木萨尔县| 海原县| 安宁市| 咸宁市| 石棉县| 邛崃市| 盘山县| 常熟市| 炎陵县| 利津县| 蓝田县| 安义县| 乌兰县| 光泽县| 余姚市| 百色市| 榆中县| 广德县| 米泉市| 清徐县| 邛崃市| 龙胜| 焦作市| 泊头市| 东阳市| 建瓯市|