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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

winfrom-畫圖學(xué)習(xí)

2019-11-11 02:35:13
字體:
供稿:網(wǎng)友

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 畫的暫存結(jié)果取回            pictureBox1.Image = img; // 然后顯示出來        }        private void FormPainter_MouseMove(object sender, MouseEventArgs e)        {            Point p = new Point(e.X, e.Y);            buf = new Bitmap(img); // 建立一個新的 buf 緩存區(qū),畫的時候            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;        }        //...    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 鄄城县| 凌云县| 克什克腾旗| 师宗县| 嘉禾县| 军事| 嵊州市| 沂南县| 昌吉市| 潞西市| 祁阳县| 乾安县| 五华县| 合肥市| 营口市| 克东县| 黄山市| 巨野县| 龙游县| 唐河县| 古蔺县| 怀宁县| 双峰县| 清水河县| 广丰县| 宁都县| 德清县| 安多县| 东阿县| 文登市| 桐城市| 翼城县| 富源县| 泰州市| 鹰潭市| 杂多县| 阿巴嘎旗| 敦化市| 承德市| 水富县| 隆昌县|