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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

winfrom-拖動(dòng)鼠標(biāo)繪制矩形

2019-11-11 02:50:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(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)            {                //實(shí)時(shí)的畫(huà)矩形                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ā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜黄县| 酉阳| 松溪县| 女性| 天峻县| 龙岩市| 和田市| 正镶白旗| 福州市| 九龙坡区| 福海县| 屏东县| 徐州市| 友谊县| 大连市| 扎赉特旗| 沙雅县| 上犹县| 偏关县| 石泉县| 澄迈县| 乐亭县| 东乡族自治县| 汤原县| 西充县| 伽师县| 抚顺市| 开鲁县| 平原县| 天全县| 大同市| 清远市| 双流县| 徐闻县| 双牌县| 抚远县| 灌南县| 重庆市| 天台县| 峡江县| 剑河县|