.net Reflection event registration

Published Jul 22, 2013 | Updated Sep 20, 2022 | 0 comments

리플렉션으로 이벤트를 등록하는 샘플

– MDI 자식 폼에서 이벤트 등록 및 호출(C#)

    public delegate void TestDelegate(object sender, string str); 
    public event TestDelegate OnTested;
    private void btnRefer_Click(object sender, EventArgs e)  {
      if(OnTested != null)   {
        OnTested(this, "test");   
      }
    }

– 메인 폼에서 리플렉션으로 해당 폼 생성 시 이벤트 등록(VB.NET)

    oUserControl = CType(oAsm.CreateInstance(aAssemblyNm & "." & aClassNm), UserControl)

    If (aAssemblyNm = "KKOMZI.Test" And aClassNm = "TST001") Then
      Dim eventInfo As EventInfo = oUserControl.GetType().GetEvent("OnTested")
      Dim type As Type = eventInfo.EventHandlerType
      Dim method As MethodInfo = Me.GetType().GetMethod("TestShow", BindingFlags.NonPublic Or BindingFlags.Instance)
      Dim handler As [Delegate] = [Delegate].CreateDelegate(type, Me, method)
      eventInfo.AddEventHandler(oUserControl, handler)
    End If

– 메인 폼에서 이벤트 발생 시 실행될 메서드(VB.NET)

    Private Sub TestShow(ByVal sender As Object, ByVal str As String)
      MessageBox.Show(str)
    End Sub

TAG INFORMATION

Learn more on this topic

Related Blog Posts

윈도우 폼 개발후 배포시 사이즈가 이상하다…?

AutoScaleMode열거형 Windows Forms에서 지원하는 여러 종류의 자동 크기 조정 모드를 지정합니다. 네임스페이스: System.Windows.Forms 어셈블리: System.Windows.Forms(System.Windows.Forms.dll) 구문 public enum AutoScaleMode 멤버 이름 설명 None 자동 크기조정을 사용할 수 없습니다. Font 클래스에서 사용하는글꼴(대개 시스템 글꼴)의 크기를 기준으로 크기를 제어합니다. Dpi...

read more
asp.net development server port issue

asp.net development server port issue

지금껏 C/S 만 위주로 개발을 하다 오랜만에 Web 관련 프로젝트를 하고있다.. 물론 Silverlight 라서 크게 문제되지는 않지만 8, 9 년 전에 PHP 하던게 Web 관련 일은 전부인지라... 이것 저것 걸리는게 많다... 그 와중에 간간히.. 때때로 매번.... Silverlight 쪽 소스 변경한 것을 확인할려고 솔루션 탐색기의 Web Project 를 디버그 모드로 실행하면("마우스 우클릭=>디버그=>새 인스턴스 시작") 위와 같은 에러가 난다......

read more

c# thread safe extension method

public static class ExtensionMethod { public static TResult SafeInvoke(this T isi, Func call) where T : ISynchronizeInvoke { if(isi.InvokeRequired) { IAsyncResult result = isi.BeginInvoke(call, new object[] { isi }); object endResult = isi.EndInvoke(result); return...

read more

Join in the conversation

Leave a Comment

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

무료 온라인 전광판

전광판

텍스트를 입력하고 텍스트 효과 및 배경효과 를 변경해서 전체화면으로 표시할 수 있는 전광판 용도로 사용하실 수 있습니다. 각종 스포츠 및 공연 관람시 응원 용도로 사용이 가능합니다.

Carousel

여러개의 슬라이드를 추가하여 프레젠테이션 및 이미지 슬라이드 용도로 사용하실 수 있습니다. 브라우저가 포함된 IT 기기로 큰 모니터에 연결하여 매장 내 공지사항 및 메뉴소개를 이미지로 표시할 수 있습니다.

Pin It on Pinterest

Shares
Share This

Share This

Share this post with your friends!

Shares