7

テキストをコピーできるカスタム メッセージ ボックスを作成していますが、標準のメッセージ ボックスとまったく同じように表示したかったので、MessageBox クラスと同様に、ボタンのテキストをシステム言語に設定したいと考えています。そのテキストを取得する方法を知っている人はいますか (「はい」、「いいえ」、「キャンセル」など)。

4

4 に答える 4

8

Snarfblam リンクで回答していただきありがとうございます。残りは理解できました。

class Program {

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);
[DllImport("kernel32")]
static extern IntPtr LoadLibrary(string lpFileName);

private const uint OK_CAPTION = 800;
private const uint CANCEL_CAPTION = 801;
private const uint ABORT_CAPTION = 802;
private const uint RETRY_CAPTION = 803;
private const uint IGNORE_CAPTION = 804;
private const uint YES_CAPTION = 805;
private const uint NO_CAPTION = 806;
private const uint CLOSE_CAPTION = 807;
private const uint HELP_CAPTION = 808;
private const uint TRYAGAIN_CAPTION = 809;
private const uint CONTINUE_CAPTION = 810;

static void Main(string[] args) {
    StringBuilder sb = new StringBuilder(256);

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

    LoadString(user32, OK_CAPTION, sb, sb.Capacity);
    string ok = sb.ToString();

    LoadString(user32, CANCEL_CAPTION, sb, sb.Capacity);
    string cancel = sb.ToString();

    LoadString(user32, ABORT_CAPTION, sb, sb.Capacity);
    string abort = sb.ToString();

    LoadString(user32, RETRY_CAPTION, sb, sb.Capacity);
    string retry = sb.ToString();

    LoadString(user32, IGNORE_CAPTION, sb, sb.Capacity);
    string ignore = sb.ToString();

    LoadString(user32, YES_CAPTION, sb, sb.Capacity);
    string yes = sb.ToString();

    LoadString(user32, NO_CAPTION, sb, sb.Capacity);
    string no = sb.ToString();

    LoadString(user32, CLOSE_CAPTION, sb, sb.Capacity);
    string close = sb.ToString();

    LoadString(user32, HELP_CAPTION, sb, sb.Capacity);
    string help = sb.ToString();

    LoadString(user32, TRYAGAIN_CAPTION, sb, sb.Capacity);
    string tryAgain = sb.ToString();

    LoadString(user32, CONTINUE_CAPTION, sb, sb.Capacity);
    string cont = sb.ToString();

}
于 2009-05-31T18:17:25.403 に答える
4

これらの文字列は、User32.dll ライブラリに格納されているようです。Pure BASIC フォーラムのこのディスカッションの下部に詳細があります。

于 2009-05-31T17:46:48.793 に答える
0

リフレクターでSystem.Windows.Forms.dllを開いて、ボタンのテキストがどのように設定されているかを確認できます。

于 2009-05-31T17:20:09.673 に答える
-2

そのメッセージを入力したときに、「はい」、「いいえ」、「OK」、「キャンセル」と入力した可能性があります。

于 2009-05-31T17:08:19.593 に答える