none
반갑습니다. RRS feed

  • 질문

  • 아직 우리나라 카테고리의 Smart Device Forum 이 활성화되지 않았네요.
    앞으로 많은 활성화를 기대합니다.
    • 이동됨 Alicia CalesMicrosoft employee 2010년 4월 14일 수요일 오전 6:57 Forums Consolidation (이전 위치:Smart Devices Native C++ Development)
    2007년 4월 28일 토요일 오전 4:17

모든 응답

  • 포럼의 존재조차 모르는 개발자들이 더 많지 않겠습니까?

    이곳보다는 데브피아에서 더 많이 활동하고 있지 않나 하는 생각입니다.

    2008년 3월 20일 목요일 오전 5:56
  • 포럼의 존재조차 모르는 개발자들이 더 많지 않겠습니까?

    이곳보다는 데브피아에서 더 많이 활동하고 있지 않나 하는 생각입니다.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;
    namespace Microsoft
    {
        public partial class Form1 : Form
        {
            public Pen mypen;
            public Point now;
            public Point start;
            public ArrayList save;
            private int drawmode;
            private bool fillFlag;
            private Pen backPen;
            private Brush myBrush;
            ArrayList save1;
           
            int[] count = new int[500];
            int i = 0;
            int totalcount = 0;
            int k;

            public Form1()
            {
                InitializeComponent();
                drawmode = 1;
                mypen = new Pen(Color.Black);       
                save = new ArrayList();
                 save1 = new ArrayList();
               
                
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                SetStyle(ControlStyles.UserPaint, true);
                this.ResizeRedraw = true;           
            }
            private void 선그리기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                drawmode = 1;
                Invalidate();
                this.Update();
            }
            private void 곡선그리기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                drawmode = 2;
                Invalidate();
                this.Update();
            }

            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left) return;
                else
                {
                    now = new Point(e.X, e.Y);
                    start = now;
                    if (drawmode != 2 && drawmode != 5)
                    {
                        count[i]++;
                    }
                }
            }
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left) return;
                else
                {               
                    now = new Point(e.X, e.Y);
                    Graphics g = this.CreateGraphics();
                    Invalidate();
                    this.Update();
                    Rectangle rect;
                    switch (drawmode)
                    {
                        case 1:
                            g.DrawLine(mypen, start, now);
                            count[i] = 1;
                            break;
                        case 2:
                            g.DrawLine(mypen, start, now);
                            DrawData inputData = new DrawData(start, now, mypen.Color, drawmode, mypen.Width);
                            save.Add(inputData);
                            SaveData sd = new SaveData(start, now, mypen.Color, drawmode, mypen.Width);
                            save1.Add(sd);
                            start = now;
                            count[i]++;
                            break;
                        case 3:
                            rect = new Rectangle(start.X, start.Y, now.X - start.X, now.Y - start.Y);
                            if (fillFlag) g.FillEllipse(myBrush, rect);
                            g.DrawEllipse(mypen, rect);
                            count[i] = 1;                   
                            break;
                        case 4:
                            rect = new Rectangle(start.X, start.Y, now.X - start.X, now.Y - start.Y);
                            if (fillFlag) g.FillRectangle(myBrush, rect);
                            g.DrawRectangle(mypen, rect);
                            count[i] = 1;
                            break;
                        case 5:
                            g.DrawLine(backPen, start, now);
                            DrawData inputData2 = new DrawData(start, now, backPen.Color, drawmode, backPen.Width);
                            save.Add(inputData2);
                            sd = new SaveData(start, now, backPen.Color, drawmode, backPen.Width);                       
                            save1.Add(sd);
                            start = now;
                            count[i]++;
                            break;
                    }
                    g.Dispose();
                }
            }
            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                DrawData inputdata;
                SaveData inputdata3;
                switch (drawmode)
                {
                    case 1:
                        inputdata = new DrawData(start, now, mypen.Color, drawmode, mypen.Width);
                        save.Add(inputdata);
                        inputdata3 = new SaveData(start, now, mypen.Color, drawmode, mypen.Width);
                        save1.Add(inputdata3);
                        break;
                    case 2:
                        break;
                    case 3:
                        inputdata = new DrawData(start, now, mypen.Color, colorBrush.Color, fillFlag, drawmode, mypen.Width);
                        save.Add(inputdata);
                        inputdata3 = new SaveData(start, now, mypen.Color, colorBrush.Color, fillFlag, drawmode, mypen.Width);
                        save1.Add(inputdata3);
                        break;
                    case 4:
                        inputdata = new DrawData(start, now, mypen.Color, colorBrush.Color, fillFlag, drawmode, mypen.Width);
                        save.Add(inputdata);
                        inputdata3 = new SaveData(start, now, mypen.Color, colorBrush.Color, fillFlag, drawmode, mypen.Width);
                        save1.Add(inputdata3);
                        break;
                    case 5:
                        break;
                }
                totalcount += count[i];
                i++;
                Invalidate();
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                Graphics g = e.Graphics;
                foreach (DrawData outdata in save)
                {
                    outdata.drawData(e.Graphics);
                }
               
            }
            private void 취소ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (save.Count > 0)
                {
                    for (k = 1; k <= count[i - 1]; k++)
                    {
                        save.RemoveAt(totalcount - k);
                    }
                    for (k = 1; k <= count[i - 1]; k++)
                    {
                        totalcount--;
                    }
                    Invalidate();
                    this.Update();
                    i--;
                    count[i] = 0;
                    if (i < 0)
                        i = 0;
                    if (totalcount < 0)
                        totalcount = 0;
                }
            }

           
            private void 화면삭제ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                save.Clear();
                save1.Clear();
                fillFlag = false;
                Invalidate();
                this.Update();
            }
            private void 원그리기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                drawmode = 3;
                Invalidate();
                this.Update();
            }
            private void 사각형그리기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                drawmode = 4;
                Invalidate();
                this.Update();
            }
            private void 펜섹ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                colorPen.ShowDialog();
                mypen.Color = colorPen.Color;
               
            }
            private void 색선택ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                fillFlag = true;           
                colorBrush.ShowDialog();
                myBrush = new SolidBrush(colorBrush.Color);
            }
            private void 널브러시ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                fillFlag = false;
            }
            private void 굵은선ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                mypen.Width = 5;
            }
            private void 보통선ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                mypen.Width = 3;
            }
            private void 가는선ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                mypen.Width = 1;
            }
            private void 종료ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            private void 지우기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                backPen = new Pen(this.BackColor);
                backPen.Width = 50;
                drawmode = 5;
                Invalidate();
                this.Update();
            }
            class DrawData
            {
                public Point startPoint;
                public Point endPoint;
                public Pen pen;
                public Color pen_color;
                public int drawMode;
                public Brush brush;
                bool fill;
                public DrawData(Point x, Point y, Color p, int dMode, float w)
                {
                    startPoint = x;
                    endPoint = y;
                    pen_color = p;
                    pen = new Pen(pen_color, w);
                    drawMode = dMode;
                }
                public DrawData(Point x, Point y, Color p, Color b, bool f, int dMode, float w)
                {
                    startPoint = x;
                    endPoint = y;
                    pen_color = p;
                    pen = new Pen(pen_color, w);
                    brush = new SolidBrush(b);
                    fill = f;
                    drawMode = dMode;
                }
               
                public void drawData(Graphics g)
                {
                    Rectangle rect;
                    switch (drawMode)
                    {
                        case 1:
                            g.DrawLine(pen, startPoint, endPoint);
                            break;
                        case 2:
                            g.DrawLine(pen, startPoint, endPoint);
                            break;
                        case 3:
                            rect = new Rectangle(startPoint.X, startPoint.Y, endPoint.X - startPoint.X,
                            endPoint.Y - startPoint.Y);
                            if (fill) g.FillEllipse(brush, rect);
                            g.DrawEllipse(pen, rect);
                            break;
                        case 4:
                            rect = new Rectangle(startPoint.X, startPoint.Y, endPoint.X - startPoint.X,
                            endPoint.Y - startPoint.Y);
                            if (fill) g.FillRectangle(brush, rect);
                            g.DrawRectangle(pen, rect);
                            break;
                        case 5:
                            g.DrawLine(pen, startPoint, endPoint);
                            break;
                    }
                }
            }
            private void 새파일ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                save.Clear();
                save1.Clear();
                fillFlag = false;
                Invalidate();
                this.Update();
            }
            private void 저장ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                saveFileDialog1.ShowDialog();
                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, save1);
                fs.Close();
                save1.Clear();
            }
            private void 열기ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                save.Clear();
                save1.Clear();
                openFileDialog1.ShowDialog();           
                FileStream fs1 = new FileStream(openFileDialog1.FileName, FileMode.Open);
                BinaryFormatter bf1 = new BinaryFormatter();
                save1 = (ArrayList)bf1.Deserialize(fs1);
                fs1.Close();
                DrawData inputdata;
                foreach (SaveData outdata in save1)
                {
                    switch (outdata.drawmode)
                    {
                        case 1:
                            inputdata = new DrawData(outdata.startPoint, outdata.nowPoint, outdata.pcolor,
                            outdata.drawmode, outdata.width);
                            save.Add(inputdata);
                            break;
                        case 2:
                            inputdata = new DrawData(outdata.startPoint, outdata.nowPoint, outdata.pcolor,
                            outdata.drawmode, outdata.width);
                            save.Add(inputdata);
                            break;
                        case 3:
                            inputdata = new DrawData(outdata.startPoint, outdata.nowPoint, outdata.pcolor,
                            outdata.bcolor, outdata.fill, outdata.drawmode, outdata.width);
                            save.Add(inputdata);
                            break;
                        case 4:
                            inputdata = new DrawData(outdata.startPoint, outdata.nowPoint, outdata.pcolor,
                            outdata.bcolor, outdata.fill, outdata.drawmode, outdata.width);
                            save.Add(inputdata);
                            break;
                        case 5:
                            inputdata = new DrawData(outdata.startPoint, outdata.nowPoint, outdata.pcolor,
                            outdata.drawmode, outdata.width);
                            save.Add(inputdata);
                            break;
                    }
                }
                Invalidate();
            }
            [Serializable]
            public class SaveData
            {
                public Point startPoint;
                public Point nowPoint;           
                public Color pcolor;
                public Color bcolor;
                public bool fill;
                public int drawmode;
                public float width;
                public SaveData(Point x, Point y, Color p, int dMode, float w)
                {
                    startPoint = x;
                    nowPoint = y;
                    pcolor = p;
                    drawmode = dMode;
                    width = w;
                }
               
                public SaveData(Point x, Point y, Color p, Color b, bool f, int dMode, float w)
                {
                    startPoint = x;
                    nowPoint = y;
                    pcolor = p;
                    bcolor = b;
                    fill = f;
                    drawmode = dMode;
                    width = w;
                }
            }     
        }
    }

    2009년 12월 8일 화요일 오후 9:50