zoukankan      html  css  js  c++  java
  • Winform在控件内实现简单画笔功能

    using System.Drawing;
    using System.Windows.Forms;
    
    namespace ZhuoHuiSchoolroom.ZhuoHuiClass
    {
        /// <summary>
        /// 实现窗体内简单画笔功能
        /// </summary>
        public class DrawClass
        {
            private Color __Color = new Color();
            private Point __Start = new Point();
            private Point __End = new Point();
            private Form __frmMain = new Form();
            private PictureBox __picMain = new PictureBox();
            private Graphics __g = null;
            private Pen __p = null;
    
            public Color Color
            {
                get { return this.__Color; }
                set { this.__Color = value; }
            }
            public Point Start
            {
                get { return this.__Start; }
                set { this.__Start = value; }
            }
            public Point End
            {
                get { return this.__End; }
                set { this.__End = value; }
            }
    
    
            public DrawClass(Form frmMain)
            : this(frmMain, Color.Black)
            { }
            public DrawClass(PictureBox picMian)
            : this(picMian, Color.Red)
            { }
    
            public DrawClass(Form frmMain, Color c)
            {
                this.__frmMain = frmMain;
                this.__g = Graphics.FromHwnd(frmMain.Handle);
                this.__Color = c;
                this.__p = new Pen(this.__Color, 2);
                this.__frmMain.MouseDown += new MouseEventHandler(__frmMain_MouseDown);
                this.__frmMain.MouseMove += new MouseEventHandler(__frmMain_MouseMove);
                this.__frmMain.MouseUp += new MouseEventHandler(__frmMain_MouseUp);
            }
    
            public DrawClass(PictureBox frmMain, Color c)
            {
                this.__picMain = frmMain;
                this.__g = Graphics.FromHwnd(frmMain.Handle);
                this.__Color = c;
                this.__p = new Pen(this.__Color, 2);
                this.__picMain.MouseDown += new MouseEventHandler(__frmMain_MouseDown);
                this.__picMain.MouseMove += new MouseEventHandler(__frmMain_MouseMove);
                this.__picMain.MouseUp += new MouseEventHandler(__frmMain_MouseUp);
            }
    
            private void __frmMain_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    __End.X = e.X;
                    __End.Y = e.Y;
                    __g.DrawLine(this.__p, __Start, __End);
                    __Start = __End;
                }
            }
    
            private void __frmMain_MouseUp(object sender, MouseEventArgs e)
            {
    
            }
    
            private void __frmMain_MouseDown(object sender, MouseEventArgs e)
            {
                this.__Start.X = e.X;
                this.__Start.Y = e.Y;
            }
    
    
        }
    }
    
    
    
    DrawClass draw = new ZhuoHuiClass.DrawClass(this.pic);                              //调用画笔功能
  • 相关阅读:
    软件工程实践第三次作业——原型设计
    第三次作业补充
    软件工程实践之词频统计
    软工实践第一次作业
    B*树索引结构和内部管理(转)
    MySQL索引背后的数据结构及算法原理(转)
    Java编程军规
    差分隐私学习三:实现机制
    万能头文件#include <bits/stdc++.h>
    微信小程序-flex布局中align-items和align-self区别
  • 原文地址:https://www.cnblogs.com/Mzg121584668/p/7452360.html
Copyright © 2011-2022 走看看