블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-29 07:22
TISTORY The Real Identity
Daum 메일 100GB, Daum 클라우드 100GB에 당첨되셨습니다.
축하합니다!

본 메일은 Tistory.com 메일 주소 오픈 이벤트에 당첨되신 분들에게 발송되는 메일입니다.
블루아사님이 2011년 7월 8일에 만드신 blueasa@tistory.com 메일의 이벤트 자동응모에 당첨되어 TISTORY 이메일(blueasa@tistory.com)과 Daum 클라우드 용량이 각각 100GB로 증대되었습니다.

넉넉한 용량의 이메일과 Daum 클라우드로 TISTORY의 자부심을 그대로 느껴보세요.
프리미엄 블로거 TISTORY 이용자분들을 위한 TISTORY의 노력은 앞으로도 계속됩니다.
Daum 메일 바로가기 Daum 클라우드 바로가기
티스토리 바로가기
Copyright © Daum Communications. All rights reserved. 고객센터 | 공지사항


그닥 홍보도 안하고해서 안될 줄 알았는데 됐네요.

용량 많이주니 나름 잘 써먹어야겠습니다. :) 
반응형

'Etc' 카테고리의 다른 글

소프트웨어, 잉여와 공포  (0) 2011.08.29
CryENGINE 3 Free SDK  (0) 2011.08.18
JSON  (0) 2011.06.16
임금체불 시뮬레이션 (이미지)  (0) 2011.05.31
낮은 자존감이 모든 문제의 근원이다  (0) 2011.05.22
Posted by blueasa
, |

내개만든 객체를 다른 객체에 이벤트를 사용하게 하기 위해서는 6가지로 나누어 볼수 있읍니다..

 

 이벤트를 발생시키는 객체서는4가지입니다

 이중 1,2는 매개 변수가 없을때 기본생성자를 사용함으로 생락 가능

 

 구독에서는 5,6번으로 폼 이벤트 사용할때 주로 사용을 많이 해봤을것으로 압니다

 

 

 이해 안되면  매개 변수가 있으면 구독 4가지,없으면 2가지 그냥 외우면 됩니다..

그리고 나만의 예제 하나 만들어 보면 모든데 이해 될것으로 생각 됩니다.

 

  

이벤트 사용하기

1.    새로운 데이터 타입 생성 [생락가능]

매개 변수가 없는 이벤트를 생성시 기본 생성자 public delegate void EventHandler(object sender, EventArgs e)를 사용하면 됨으로 생략 ,여기서는 minEventHandler라는 새로은 데이터 타입

public delegate void minEventHandler(object sender,minEventTestArgs e);//델리게이트 선언

 

2. 이벤트 매개 변수를 위한 객체 생성 [생락가능]

     1번의 두 번째 매개 변수에 사용하기 위한 객체로서 매개 변수로 넘길 데이터가 없으면 그냥 EventArg를 사용해도 됨.

public class minEventTestArgs : EventArgs

        {

        public DateTime m_Timer{get;set;}

        public minEventTestArgs(DateTime Timer)

        {

            this.m_Timer = Timer;

        }

  

3. 이벤트 정의 a 1번의 인터페이스

public event minEventHandler minEventTest;  // 이벤트 정의

 

4. 이벤트 발생

public void OnMinEventTest(minEventTestArgs e)  // 이벤트 발생 구독자에게 통보

        {

            if (minEventTest != null)

                minEventTest(this, e);

 }

 

 

-----------------------------------------------------

5. 이벤트 핸들러 메소드

minTimer min;  //       

  private void Form1_Load(object sender, EventArgs e)

  {

            min = new minTimer();

            min.minEventTest += new minEventHandler(min_minEventTest);

 }

 

6. 이벤트 구독

Void min_minEventTest(object sender, minEventTestArgs e)

       {

            textBox1.Text = e.m_Timer.ToLongTimeString();

       }

 

 

=========================================================================================== 

여기서 부터 는  예제

1 minTimer라는 객체를 하나 만들고

이 객체는 1초마다 현재 시간을 알려주는 이벤트를 생성한는일을 함.

2 폼 에서는 minTimer객체 인터페이스를 만들고 이벤트를 구독한다

 

using System;

namespace WindowsFormsApplication1

{  

    public delegate void minEventHandler(object sender,minEventTestArgs e); //새로운 객체

    public class minTimer

    {

        System.Windows.Forms.Timer timer;               //시간을 읽어오는 타이머

      

        public event minEventHandler minEventTest;         //[2] 이벤트 정의

        public void OnMinEventTest(minEventTestArgs e)  //[3] 이벤트 발생 구독자에게 통보

        {

            if (minEventTest != null)

                minEventTest(this, e);

        }

 

        //

        public minTimer()

        {

            timer = new System.Windows.Forms.Timer();

            timer.Interval = 1000;

            timer.Enabled = true;

            timer.Start();

            timer.Tick += new EventHandler(timer_Tick);

        }

 

        //

        void timer_Tick(object sender, EventArgs e)

        {

            DateTime curTime = DateTime.Now;

            minEventTestArgs args = new minEventTestArgs(curTime);

            OnMinEventTest(args);

        }

    }

 

    // [1] 이벤트 인자를 위한 객체

    public class minEventTestArgs : EventArgs

    {

        public DateTime m_Timer{get;set;}

        public minEventTestArgs(DateTime Timer)

        {

            this.m_Timer = Timer;

        }

    }

}

 

-----------------------------------------------------------------------

폼에서

minTimer min; //       

        private void Form1_Load(object sender, EventArgs e)

        {

            min = new minTimer();

            min.minEventTest += new EventHandler(min_minEventTest);

         }

 

        void min_minEventTest(object sender, minEventTestArgs e)

        {

            textBox1.Text = e.m_Timer.ToLongTimeString();

        }

 

 

 

잘못된부분 있으면 정보 공유 차원에서라도

답글 부탁 합니다,


출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=18&MAEULNO=8&no=1831&page=4

반응형

'Programming > C#' 카테고리의 다른 글

interface(C# 참조)  (0) 2010.09.14
abstract(C# 참조)  (0) 2010.09.14
STL map == C# Dictionary  (0) 2010.09.13
자동 업데이트 프로그램  (1) 2010.09.10
간단한 자동 업데이트 프로그램 구현  (0) 2010.09.10
Posted by blueasa
, |