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

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

winfrom-拖動鼠標繪制矩形

2019-11-11 02:42:03
字體:
來源:轉載
供稿:網友

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


上一篇:C#抽象類總結

下一篇:獎券數目

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新乡市| 五常市| 文昌市| 托里县| 湖口县| 北宁市| 连山| 肇东市| 巩义市| 云林县| 安平县| 大宁县| 西平县| 三原县| 罗江县| 西畴县| 阿勒泰市| 道孚县| 会理县| 新蔡县| 开阳县| 闻喜县| 崇左市| 吴忠市| 澄江县| 邮箱| 乐安县| 湄潭县| 城口县| 浮山县| 赞皇县| 涿鹿县| 凤冈县| 交口县| 保靖县| 林周县| 南开区| 山东| 甘孜| 贞丰县| 濉溪县|