locked
Android application RRS feed

  • 질문

  • Android application

     javascript

    iphone

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Collections;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;

    namespace
    {
         public partial class Form1 : Form
         {
              public int drawMode; // 그리기 모드
              public Point startPoint;// 시작 점
              public Point nowPoint; // 현재 점
              public Pen myPen; // 펜
              public Brush myBrush;// 브러쉬
              public ArrayList saveData; // 그림 객체 정보 저장
              public ArrayList saveData2;
              public ArrayList saveData3;// 자유곡선 정보 저장
              public bool fillFlag;// 채우기 선택
              public int rm;
              public int count;
              public int count2;
              public int count3;
              public int count4;
              public float okay = 0;
              public FileStream fs;

              public Form1()
              {
                   InitializeComponent();
                   drawMode = 1; // 선 그리기로 초기화
                   fillFlag = false;
                   myPen = new Pen(Color.Black);
                   saveData = new ArrayList();
                   saveData2 = new ArrayList();
                   saveData3 = new ArrayList();
                   al = new ArrayList();
              }


              private void 종료ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   Close();
              }

              private void Form1_Load(object sender, EventArgs e)
              {
                   SetStyle(ControlStyles.DoubleBuffer, true);
                   SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                   SetStyle(ControlStyles.UserPaint, true);
                   ResizeRedraw = true;
              }

              private void 선ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                  myPen.Color = colorDialog1.Color;
                  myPen.Width = okay;
                   drawMode = 1; // 선 그리기
                   Invalidate(); // 컨트롤의 전체 화면을 무효화하고 컨트롤을 다시 그린다.
                   Update(); //컨트롤의 클라이언트 영역 내에 무효화된 영역을 다시 그리게 한다.
              }

              private void 원ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                  myPen.Color = colorDialog1.Color;
                  myPen.Width = okay;
                   drawMode = 2;
                   Invalidate();
                   Update();  // 원 그리기
              }

              private void 사각형ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                  myPen.Color = colorDialog1.Color;
                  myPen.Width = okay;
                   drawMode = 3;
                   Invalidate();
                   Update();  // 사각형 그리기
              }

              private void 곡선ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                  myPen.Color = colorDialog1.Color;
                  myPen.Width = okay;
                   drawMode = 4;
                   Invalidate();
                   Update();  // 곡선 그리기
              }

              private void 화면삭제ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   saveData.Clear();
                   fillFlag = false;
                   Invalidate();
                   Update();
              }

              private void 취소ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   if (saveData.Count > 0)
                   { //그림 객체가 있다면
                        int rem = (int)saveData3[saveData3.Count-1];                    
                        if (rem == 1)
                        {
                             int count5 = (int)saveData2[saveData2.Count - 1];                         
                             for (int i = 0; i <= count5; i++)                              
                                  saveData.RemoveAt(saveData.Count - 1);
                             saveData3.RemoveAt(saveData3.Count - 1);
                             saveData2.RemoveAt(saveData2.Count - 1);
                             Invalidate();
                             Update();                         
                        }
                        else
                        {
                             saveData.RemoveAt(saveData.Count - 1); //마지막 객체를 제거
                             saveData3.RemoveAt(saveData3.Count - 1);
                             Invalidate();
                             Update();
                        }
                   }
              }

              private void 펜색ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   colorDialog1.ShowDialog();
                   myPen.Color = colorDialog1.Color;
              }

              private void 브러쉬ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   fillFlag = true;
                   colorDialog2.ShowDialog();
                   myBrush = new SolidBrush(colorDialog2.Color);
              }

              private void 일반ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   fillFlag = false;
              }

              private void 볼드ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   myPen.Width = 5;
                   okay = myPen.Width;
              }

              private void 노말ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   myPen.Width = 3;
                   okay = myPen.Width;
              }

              private void 가늘게ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   myPen.Width = 1;
                   okay = myPen.Width;
              }

              private void Form1_MouseDown(object sender, MouseEventArgs e)
              {
                   if (e.Button != MouseButtons.Left) return;
                   Cursor = Cursors.Cross;// 커서를 십자가 커서로 변경
                   nowPoint = new Point(e.X, e.Y); // 현재 마우스의 위치
                   startPoint = nowPoint; // 선의 시작점의 위치를 설정
                   count3 = saveData.Count;
              }

              private void Form1_MouseMove(object sender, MouseEventArgs e)
              {
                   //왼쪽마우스 눌려져있지 않으면 곡선을 그리지 않는다.
                   if (e.Button != MouseButtons.Left)
                        return;
                   nowPoint = new Point(e.X, e.Y); // 현재 마우스의 위치
                   Graphics g = CreateGraphics(); Invalidate(); // 무효화
                   Update(); //무효화 시킨 영역을 다시 그리기
                   Rectangle rect;

                   switch (drawMode)
                   {
                        case 1:                        
                             g.DrawLine(myPen, startPoint, nowPoint);                         
                             break;
                        case 2:                         
                             rect = new Rectangle(startPoint.X, startPoint.Y, nowPoint.X - startPoint.X, nowPoint.Y - startPoint.Y);
                             if (fillFlag)
                                  g.FillEllipse(myBrush, rect);
                             else
                                  g.DrawEllipse(myPen, rect);
                             break;
                        case 3:                         
                             rect = new Rectangle(startPoint.X, startPoint.Y, nowPoint.X - startPoint.X, nowPoint.Y - startPoint.Y);
                             if (fillFlag)
                                  g.FillRectangle(myBrush, rect);
                             else
                                  g.DrawRectangle(myPen, rect);
                             break;
                        case 4:                                                 
                             g.DrawLine(myPen, startPoint, nowPoint);
                             DrawData inputData = new DrawData(startPoint, nowPoint, myPen.Width, myPen.Color, drawMode);                         
                             count++;
                             count4 = saveData.Count;                     
                             saveData.Add(inputData);
                             al.Add(inputData);
                             startPoint = nowPoint;                         
                             break;
                   }
                   g.Dispose();
              }

              private void Form1_MouseUp(object sender, MouseEventArgs e)
              {
                   if (e.Button != MouseButtons.Left)
                        return;
                   DrawData inputData;
                   switch (drawMode)
                   {
                        case 1: // 선 그리기
                              rm = 0;
                             saveData3.Add(rm);
                             inputData = new DrawData(startPoint, nowPoint, myPen.Width, myPen.Color, drawMode);                    
                             saveData.Add(inputData);                         
                             break;

                        case 2: // 원 그리기
                              rm = 0;
                             saveData3.Add(rm);
                             inputData = new DrawData(startPoint, nowPoint, fillFlag, drawMode, myPen.Width, myPen.Color, colorDialog2.Color);
                             saveData.Add(inputData);

                             break;
                        case 3: // 사각형 그리기
                              rm = 0;
                             saveData3.Add(rm);
                             inputData = new DrawData(startPoint, nowPoint, fillFlag, drawMode, myPen.Width, myPen.Color, colorDialog2.Color);
                             saveData.Add(inputData);

                             break;
                        case 4:                 
                              rm = 1;
                             saveData3.Add(rm);
                             count2 = count4 - count3;
                             saveData2.Add(count2);
                             break;
                   }
                   this.Cursor = Cursors.Arrow;
              }

              protected override void OnPaint(PaintEventArgs e)
              {
                   Graphics g = e.Graphics;              
                   foreach (DrawData outData in saveData)
                   {
                        outData.drawData(e.Graphics);
                   }
              }

              private void 새파일ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   if (saveData.Count > 0)
                   {
                        if (MessageBox.Show("저장하시겟습니다.", "새파일", MessageBoxButtons.OKCancel) == DialogResult.Yes)
                        {
                             saveFileDialog1.ShowDialog();
                             fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                             BinaryFormatter bf = new BinaryFormatter();
                             bf.Serialize(fs, saveData);
                             fs.Close();
                             saveData.Clear();
                             Invalidate();
                             Update();
                        }
                        else
                        {
                             saveData.Clear();
                             Invalidate();
                             Update();
                        }
                   }
                   else
                   {
                        saveData.Clear();
                        Invalidate();
                        Update();
                   }
              }

              private void 저장ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   saveFileDialog1.ShowDialog();
                   fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                   BinaryFormatter bf = new BinaryFormatter();
                   bf.Serialize(fs, saveData);
                   bf.Serialize(fs, saveData2);
                   bf.Serialize(fs, saveData3);
                   fs.Close();
                   saveData.Clear();
                   saveData2.Clear();
                   saveData3.Clear();
                   Invalidate();
                   Update();  
              }

              private void 읽기ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   openFileDialog1.ShowDialog();
                   FileStream fs1 = new FileStream(openFileDialog1.FileName, FileMode.Open);               
                   BinaryFormatter bf1 = new BinaryFormatter();
                   saveData = (ArrayList)bf1.Deserialize(fs1);
                   saveData2 = (ArrayList)bf1.Deserialize(fs1);
                   saveData3 = (ArrayList)bf1.Deserialize(fs1);
                   foreach (DrawData i in saveData)
                   {                    
                        Invalidate();
                        Update();
                   }
                   fs1.Close();
              }

              private void 지우기ToolStripMenuItem_Click(object sender, EventArgs e)
              {
                   myPen = new Pen(this.BackColor);
                   myPen.Width = 10;
                   drawMode = 4;
                   Invalidate();
                   Update();  // 곡선 그리기
              }
         }
    }

                                                      
    2015년 12월 15일 화요일 오전 2:52

모든 응답

  • 안녕하세요,

    안타깝게도 문의하고자 하시는 내용이 게시물 상에 포함되어 있지 않아 적절한 지원을 드리기가 어렵습니다. 따라서 번거로우시겠지만, 하단에 있는 [응답]을 클릭하셔서 겪고 계신 문제에 대한 설명 또는 궁금하신 점에 대하여 기재해주시면 감사하겠습니다.

    2015년 12월 15일 화요일 오전 3:33