none
ㅎㄷㄷㄷ RRS feed

  • 질문

  • using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace 정동남_숙제14
    {
        public partial class Form1 : Form
        {
            ArrayList al = new ArrayList();

            Brush br;
            Brush ebr;
            Point StartPoint;
            Point PrePoint;
            public int PreW = 0;
            public int PreH = 0;

            public Form1()
            {
                InitializeComponent();
                br = new SolidBrush(this.BackColor);
                ebr = new SolidBrush(this.BackColor);
            }

            private void 색깔CToolStripMenuItem_Click(object sender, EventArgs e)
            {
                colorDialog1.ShowDialog();
                br = new SolidBrush(colorDialog1.Color);
            }

            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left)
                    return;

                Point newPoint = new Point(e.X, e.Y);
                StartPoint = newPoint;
                PrePoint = newPoint;
            }

            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    Graphics G = this.CreateGraphics();

                    Point newPoint = new Point(e.X, e.Y);

                    int width = newPoint.X - StartPoint.X;
                    int height = newPoint.Y - StartPoint.Y;

                    Rectangle PreRect = new Rectangle(StartPoint.X, StartPoint.Y, PreW, PreH);
                    Rectangle Rect = new Rectangle(StartPoint.X, StartPoint.Y, width, height);

                    G.FillEllipse(ebr, PreRect);
                    G.FillEllipse(br, Rect);

                    PreW = width;
                    PreH = height;
                }
            }

            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                Graphics G = this.CreateGraphics();

                Point newPoint = new Point(e.X, e.Y);

                int width = newPoint.X - StartPoint.X;
                int height = newPoint.Y - StartPoint.Y;

                Rectangle Rect = new Rectangle(StartPoint.X, StartPoint.Y, width, height);

                G.FillEllipse(br, Rect);

                al.Add(br);
                al.Add(Rect);
            }

            protected override void OnPaint(PaintEventArgs e)
            {
                Graphics G = e.Graphics;
               
                int i;
                for (i = 0; i < al.Count; i = i + 2)
                {
                    G.FillEllipse((Brush)al[i], (Rectangle)al[i + 1]);
                }
            }
        }
    }

    2009년 12월 9일 수요일 오전 4:23