这是我用的代码......
MessageBox.Show("Do you want to save changes..?", "Save", MessageBoxButtons.YesNoCancel);
Run Code Online (Sandbox Code Playgroud)
我想改变消息框按钮上的文字是否有可能.. ??
据我所知,无法更改MessageBox弹出窗口上的默认文本.
最简单的方法是创建一个带有标签和几个按钮的简单表单.这是一个可用于放入代码的简单示例.您可以根据需要自定义表单.
public class CustomMessageBox:System.Windows.Forms.Form
{
Label message = new Label();
Button b1 = new Button();
Button b2 = new Button();
public CustomMessageBox()
{
}
public CustomMessageBox(string title, string body, string button1, string button2)
{
this.ClientSize = new System.Drawing.Size(490, 150);
this.Text = title;
b1.Location = new System.Drawing.Point(411, 112);
b1.Size = new System.Drawing.Size(75, 23);
b1.Text = button1;
b1.BackColor = Control.DefaultBackColor;
b2.Location = new System.Drawing.Point(311, 112);
b2.Size = new System.Drawing.Size(75, 23);
b2.Text = button2;
b2.BackColor = Control.DefaultBackColor;
message.Location = new System.Drawing.Point(10, 10);
message.Text = body;
message.Font = Control.DefaultFont;
message.AutoSize = true;
this.BackColor = Color.White;
this.ShowIcon = false;
this.Controls.Add(b1);
this.Controls.Add(b2);
this.Controls.Add(message);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以从需要的地方拨打此电话:
CustomMessageBox customMessage = new CustomMessageBox(
"Warning",
"Are you sure you want to exit without saving?",
"Yeah Sure!",
"No Way!"
);
customMessage.StartPosition = FormStartPosition.CenterParent;
customMessage.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10392 次 |
| 最近记录: |