![](/img/trans.png)
[英]How can I replace text of MessageBox (title,caption) with defined string?
[英]How do I get MessageBox button caption?
我正在创建一个允许您复制文本的自定义消息框,但我希望它看起来与标准消息框完全相同,所以我想将按钮文本设置为系统语言,就像MessageBox类一样。 有谁知道如何获得该文本(“是”,“否”,“取消”等)?
感谢您使用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();
}
这些字符串似乎存储在User32.dll库中。 关于Pure BASIC论坛的讨论有详细介绍。
在codeproject.com上有一篇关于本地化消息框的文章 - 你可能会发现这个链接很有用......
http://www.codeproject.com/KB/miscctrl/Localizing_MessageBox.aspx
希望它有帮助:)
您可以在Reflector中打开System.Windows.Forms.dll,看看它是如何设置按钮文本的。
在您键入该消息时,您可以键入“是”,“否”,“确定”,“取消”...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.