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

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

winfrom-畫圖學習

2019-11-11 03:57:44
字體:
來源:轉載
供稿:網友

namespace Painter{    partial class FormPainter    {                PRivate System.ComponentModel.IContainer components = null;        protected override void Dispose(bool disposing)        {            if (disposing && (components != null))            {                components.Dispose();            }            base.Dispose(disposing);        }              private void InitializeComponent()        {            this.toolStrip1 = new System.Windows.Forms.ToolStrip();            this.toolStripComboBoxMode = new System.Windows.Forms.ToolStripComboBox();            this.pictureBox1 = new System.Windows.Forms.PictureBox();            this.toolStrip1.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();            this.SuspendLayout();            //             // toolStrip1            //             this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {            this.toolStripComboBoxMode});            this.toolStrip1.Location = new System.Drawing.Point(0, 0);            this.toolStrip1.Name = "toolStrip1";            this.toolStrip1.Size = new System.Drawing.Size(468, 25);            this.toolStrip1.TabIndex = 0;            this.toolStrip1.Text = "toolStrip1";            //             // toolStripComboBoxMode            //             this.toolStripComboBoxMode.Items.AddRange(new object[] {            "畫筆",            "直線",            "矩形",            "圓形"});            this.toolStripComboBoxMode.Name = "toolStripComboBoxMode";            this.toolStripComboBoxMode.Size = new System.Drawing.Size(75, 25);            this.toolStripComboBoxMode.Text = "畫筆";            //             // pictureBox1            //             this.pictureBox1.Location = new System.Drawing.Point(0, 28);            this.pictureBox1.Name = "pictureBox1";            this.pictureBox1.Size = new System.Drawing.Size(456, 381);            this.pictureBox1.TabIndex = 1;            this.pictureBox1.TabStop = false;            this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormPainter_MouseDown);            this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.FormPainter_MouseMove);            this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.FormPainter_MouseUp);            //             // FormPainter            //             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.ClientSize = new System.Drawing.Size(468, 421);            this.Controls.Add(this.pictureBox1);            this.Controls.Add(this.toolStrip1);            this.Name = "FormPainter";            this.Text = "Form1";            this.toolStrip1.ResumeLayout(false);            this.toolStrip1.PerformLayout();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();            this.ResumeLayout(false);            this.PerformLayout();        }        private System.Windows.Forms.ToolStrip toolStrip1;        private System.Windows.Forms.ToolStripComboBox toolStripComboBoxMode;        private System.Windows.Forms.PictureBox pictureBox1;    }}
using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;namespace Painter{    public partial class FormPainter : Form    {        Graphics g;        Bitmap img;        Bitmap buf;        Pen pen = new Pen(Color.Black, 3);        public FormPainter()        {            InitializeComponent();            img = new Bitmap(pictureBox1.Width, pictureBox1.Height);            g = Graphics.FromImage(img);        }        bool isMouseDown = false;        List<Point> points = new List<Point>();        private void FormPainter_MouseDown(object sender, MouseEventArgs e)        {            Point p = new Point(e.X, e.Y);            isMouseDown = true;            points.Clear();            points.Add(p);            pictureBox1.Image = img;        }        private void FormPainter_MouseUp(object sender, MouseEventArgs e)        {            isMouseDown = false;            img = buf; // 將上次 MouseMove 畫的暫存結果取回            pictureBox1.Image = img; // 然后顯示出來        }        private void FormPainter_MouseMove(object sender, MouseEventArgs e)        {            Point p = new Point(e.X, e.Y);            buf = new Bitmap(img); // 建立一個新的 buf 緩存區,畫的時候            Graphics g = Graphics.FromImage(buf);            if (points.Count > 0 && isMouseDown)            {                Point pStart = points[0];                Point pLast = points[points.Count - 1];                if (toolStripComboBoxMode.Text.Equals("畫筆"))                {                    Point p0 = pStart;                    foreach (Point p1 in points)                    {                        g.DrawLine(pen, p0, p1);                        p0 = p1;                    }                }                else if (toolStripComboBoxMode.Text.Equals("直線"))                {                    g.DrawLine(pen, pStart, p);                }                else if (toolStripComboBoxMode.Text.Equals("矩形"))                {                    g.DrawRectangle(pen, pStart.X, pStart.Y, p.X - pStart.X, p.Y - pStart.Y);                }                else if (toolStripComboBoxMode.Text.Equals("圓形"))                {                    g.DrawEllipse(pen, pStart.X, pStart.Y, p.X - pStart.X, p.Y - pStart.Y);                }            }            points.Add(p);            pictureBox1.Image = buf;        }        //...    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 井研县| 普兰县| 鹿泉市| 锡林浩特市| 鄯善县| 浮山县| 颍上县| 上高县| 乌拉特后旗| 莱州市| 丰镇市| 通化县| 肇州县| 盐源县| 浦县| 丰城市| 新建县| 江油市| 富蕴县| 淳安县| 德安县| 茂名市| 醴陵市| 沅陵县| 枣庄市| 万年县| 和硕县| 东乡县| 姚安县| 清远市| 岱山县| 共和县| 寿阳县| 富宁县| 安溪县| 黄陵县| 宁安市| 布尔津县| 平定县| 湘西| 教育|