zoukankan      html  css  js  c++  java
  • C#画图

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace 事件
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private Graphics my;
            string pensColor = "Black";
           
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                Rectangle re = new Rectangle();
                if (e.Button != MouseButtons.Left) return;
    
                re.X = e.X - 1;
                re.Y = e.Y - 1;
                re.Width = 4;
                re.Height = 4;
                
                switch (pensColor)
                {
                    case "Green": my.DrawEllipse(System.Drawing.Pens.Green, re);
                        break;
                    case "Red": my.DrawEllipse(System.Drawing.Pens.Red, re);
                        break;
                    case "Blue": my.DrawEllipse(System.Drawing.Pens.Blue, re);
                        break;
                    //case default() :break;
                }
                
            }
    
            private void draw(Color c)
            {
                
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                my = this.CreateGraphics();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                pensColor = "Green";//button3.BackColor.ToString();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                pensColor = "Blue";//button2.BackColor.ToString();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                pensColor = "Red"; //button1.BackColor.ToString();
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                this.Refresh();
            }
        }
    }

    运行程序便可在窗体内进行画图,可去掉switch语句调用默认颜色进行画图操作!

  • 相关阅读:
    最小树形图 朱刘算法模板+建边技巧
    模板倍增LCA 求树上两点距离 hdu2586
    【瞎搞题】gym226123 L. For the Honest Election
    【凸包板题】Gym
    集合3
    集合2
    集合1
    常用API&异常
    内部类&API
    多态&接口类&接口
  • 原文地址:https://www.cnblogs.com/jamse/p/3404530.html
Copyright © 2011-2022 走看看