티스토리 뷰

using System;

using System.Windows.Forms;


namespace test_Console_N_Window_HdlEvt

{

    class MainApp : System.Windows.Forms.Form

    {

        public void MyMouseHandler(object sender, MouseEventArgs e)

        {

            Console.WriteLine("Sender : {0}", ((Form)sender).Text);

            Console.WriteLine("X:{0} Y:{1}", e.X, e.Y);

            Console.WriteLine("Button:{0}, Clicks:{1}", e.Button, e.Clicks);


            Console.WriteLine();

        }


        public MainApp(string title)

        {

            this.Text = title;

            this.MouseDown += new MouseEventHandler(MyMouseHandler);

        }


        static void Main(string[] args)

        {

            Application.Run(new MainApp("Mouse Event Test"));

        }

    }

}


Console 환경에서 개발. Main 에서 Run () -> MouseEventhandler 를 통해서 
sender 와 MouseEventArgs의 e 를 통해서 값 확인 가능

MyMouseHandler 에서 클릭에 대한 이벤트로 들어갔고 X 좌표 Y좌표 어떤 버턴을 클릭했는지를 확인가능.

댓글
댓글쓰기 폼