본문 바로가기
.Net

C# - MessageBox의 OK, Yes, No 등의 버튼 텍스트 얻기

by Dokon Jang 2015. 4. 15.
반응형

다국어 지원 개발을 하다보면 MessageBox의 버튼텍스트가 필요합니다..

MessageBox의 버튼의 텍스트는 User32.dll에 포함되어있습니다.

버튼의 텍스트를 가지고 오는 방법은 아래와 같습니다.

 

public const uint OK_CAPTION = 800;

public const uint CANCEL_CAPTION = 801;

public const uint ABORT_CAPTION = 802;

public const uint RETRY_CAPTION = 803;

public const uint IGNORE_CAPTION = 804;

public const uint YES_CAPTION = 805;

public const uint NO_CAPTION = 806;

public const uint CLOSE_CAPTION = 807;

public const uint HELP_CAPTION = 808;

public const uint TRYAGAIN_CAPTION = 809;

public const uint CONTINUE_CAPTION = 810;



[DllImport("kernel32")]

public static extern IntPtr LoadLibrary(string dllFileName);



[DllImport("user32.dll")] 

public static extern IntPtr LoadString(IntPtr instance, uint id, StringBuilder lpBuffer, int bufferMax); 

 

 

 

StringBuilder okValue = new StringBuilder(256);

StringBuilder yesValue = new StringBuilder(256);



IntPtr user32 = LoadLibrary(Environment.SystemDirectory + @"\User32.dll");



LoadString(user32, OK_CAPTION, okValue, okValue.Capacity); 

LoadString(user32, YES_CAPTION, yesValue, yesValue.Capacity)
반응형

태그

,

댓글0