출처 : http://windstop.tistory.com/22


아래와 같이 GetCurrentMethod을 사용하면된다. GetCurrentMethod을 사용하게 되는 경우, Debugging시 어디서 Fail이 발생되었는지 확인이 쉬워진다. 이와 더불어 LR과 같은 현재 Function을 알려주는 Method가 있으면 좋겠지만, 찾지를 못했다.


using System.Reflection;

MethodBase.GetCurrentMethod().Name; 


더 자세한 함수 호출관계를 알려면 StackTrace, StackFrame, MethodBase 클래스들을 잘 섞어쓰면 된다. 

(관련예제 자세한 것)

(http://www.codeproject.com/KB/dotnet/MethodName.aspx )

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

C# File Drag & Drop  (0) 2011.11.20
오랜만에 작성하는 포스팅이다.

회사생활을 하던 중 필요할것같은 프로그램을 만들자라는 생각이 들어 오늘부터 시작했다.
(사실 전체 디자인도 안했다.......망했다...)

아무튼 Rich Text Box에서 File Drag & Drop을 구현을 하였다.

원래 C#에서 쉽게 구현할 수 있을 것이라 생각하면서 시작하였으나, 바로 문제점이 보이기 시작하였다..
AllowDrop이라는 멤버변수를 찾지 못하겠는것이다..
봐라... 없다....
내 Development환경이 이상한건지 아니면 원래 없는것인지 모르겠으나, 아무튼 꼭 Design 창에서만 Allow Drop을 설정할수 있는것은 아니기에, Code에서 직접 넣기로하였다.



Setting 할것은 3가지이다(Design창에서 AllowDrop설정을 하였다면 2가지..)
첫째. AllowDrop 활성화 및 이벤트 연결
둘째. DragEnter 이벤트 입력
셋째. DragDrop 이벤트 입력
그럼 바로 Code 공개

1. AllowDrop 활성화 및 이벤트 연결
public frmMain()
{
        InitializeComponent();
        txtFileList.AllowDrop = true;
        txtFileList.DragDrop += new DragEventHandler(txtFileList_DragDrop);
        txtFileList.DragEnter += new DragEventHandler(txtFileList_DragEnter);
 }

2. DragEnter 이벤트 입력
void txtFileList_DragEnter(object sender, DragEventArgs e)
{
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.Copy | DragDropEffects.Scroll;
        }
}

3. DragDrop 이벤트 입력
void txtFileList_DragDrop(object sender, DragEventArgs e)
{
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            string[] strFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string strFile in strFiles)
            {
                txtFileList.Text += strFile + "\r\n";
            }
        }
}

사실 Code는 정말 쉽다.. 그래서 주석도 없다(변명이다.).. 그리고 중간 부분에 Rich Text Box에서 구현하였다고하였으나,,왠만한 모든 Form Control에는 Drag Drop을 할수있도록 멤버변수 및 메서드가 있으니, 가져다 쓰기만 하면 될것이다.

또한 Drag Drop 이벤트 입력에서 foreach 문을 써 String 하나씩 입력하였으나, 이것은 앞으로의 내 프로그램의 확장성을 고려하여 이렇게 입력하였고, "txtFileList.Lines = strFiles;"  <--이렇게 입력하여도 된다.

아무튼 성의를 보이고 싶어도 보일 수 없는 File Drag&Drop 이다.

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

C# 현재 실행중인 함수 이름 가져오기  (0) 2012.02.13
오늘 일을 하면서 알아낸 사실

만약 각 소스들이 이렇게 입력되어있다면
test1.h
#ifndef _TEST_h
#define _TEST_h

#include<stdio.h>
void printtest();
#endif

test1.c
void printtest()
{
printf("%d",1);
}

위의 소스를 include한 다른 소스

test2.h
#include<stdio.h>
#include "test1.h"
void test();

test1.c
void test()
{
printtest();
}

이렇게 정의하여 프로그램을 진행한다면 문제가 되지 않는다. 다만 어제와 오늘 삽질했던일은 무엇이냐면

test3.h
#include "test2.h"

test3.cpp
void maintest();
void maintest()
{
test();
}
위의 소스가 문제이다. 생각해서는 test2.h를 include를 했기 때문에 test()함수를 쓸수 있다라고 생각하겠지만 사실 이렇게하면 에러가 생긴다 -_-;

그래서 이 에러를 수정하기 위해서는

test2.h
#include<stdio.h>
#include "test1.h"
extern "C" {
void test();
}

test3.h
#include "test2.h"

test3.cpp
extern void test();
void maintest();
void maintest()
{
test();
}

다음과 같이 정의를 해주어야 외부함수를 호출할 수가 있다.
내 머리속과 컴퓨터 머리속은 다른가보다 extern은 알았지만 test2.h에서 extern void test(); 이렇게 선언만 해주고 다른 소스에서 쓸려니 안되어서 찾아봤더니 위와같이 하면 처리할수 있었다.
다음에 그림으로 추가 설명하겠다.

+ Recent posts