프로그래밍

C# 폼에다가 마우스로 선그리기 어떻게하나요??

by Question posted Nov 29, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

위로 아래로 댓글로 가기 인쇄 쓰기 목록
?
  • 예제 올려 드립니다.



    제목 없음.png  



    여기에 코드를 입력해주세요public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                // 화면 클리어
                this.Refresh();
            }
    
            // 마지막 마우스 클릭 위치
            Point m_LastPos = new Point(0, 0);
    
            // brush 생성
            System.Drawing.SolidBrush brushBlue = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
            
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if ((e.Button & System.Windows.Forms.MouseButtons.Left) == System.Windows.Forms.MouseButtons.Left)
                {
                    using (System.Drawing.Graphics oGraphics = this.CreateGraphics())
                    {
                        if (m_LastPos != new Point(0, 0))
                        {
                            oGraphics.DrawLine(new Pen(Color.Blue), e.X, e.Y, m_LastPos.X, m_LastPos.Y);
                        }
                        oGraphics.FillEllipse(brushBlue, e.X, e.Y, 1, 1);
                        m_LastPos = e.Location;
                    }
                }
            }
    
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                m_LastPos = e.Location;
            }
    
            private void pictureBox1_Click(object sender, EventArgs e)
            {
                try
                {
                    using (System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"http://whiteat.com/WhiteAT_Csharp"))
                    { }
                }
                catch { }
            }
        }