.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

중국어 간자체 변환

Public Function ToSCUnicode(ByVal str As String) As String Dim arrByte_GBK As Byte() Dim arrByte_UTF16 As Byte() Dim strUTF16 As String ' 현재 시스템 인코딩 Dim _defaultEncoding As Encoding = System.Text.Encoding.GetEncoding(0) ' Chinese Simplified (GB2312) Dim encGBK As...

read more
DevExpress DisableThreadingProblemsDetection

DevExpress DisableThreadingProblemsDetection

DevExpress 를 8.1.6 을 쓰다가 전체적으로 8.3.3 으로 업그레이드 했다… 리빌드 할땐 문제없다… but… 런타임에 에러가 생긴다… 머지?? 처음엔 내가 Catch 안한 오류가 있나 해서 소스를 다시 한번 살펴봤다… 근데.. 소스는 바뀐게 없는데… 이상하다 그래서 자세히 살펴보니 Cross Thread… 얼레.. 분명히 왠만한건 InvokeRequired 체크해서 다 되어있는데…. 물론 이 부분도 소스를 수정하지 않았기 때문에 이전에 없던 문제인데…...

read more

DevExpress XtraGrid 에서 선택된 행 유지

출처 : http://www.devexpress.com/Support/Center/KB/p/A364.aspx?searchtext=two+gridview&tid=4b2d6f97-c4ae-48fc-87f6-8c5da6541e40&pid=-1 정렬 이벤트에서 미리 View 와 Rowhandle 을 잡아두고 정렬이 끝나면 이전 잡아둔 행으로 이동새로고침 될때 사용하면 되겠네… using DevExpress.XtraGrid; using...

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