实现效果:
public partial class CustomMessageBox : Form { // 声明按钮和标签控件 private Button btnOption1; private Button btnOption2; private Label lblMessage; // 自定义属性用于获取对话框的结果 public DialogResult DialogResult1 { get; private set; } // 构造函数,初始化自定义消息框 public CustomMessageBox(string message, string button1Text, string button2Text) { // 初始化消息标签并设置其属性 lblMessage = new Label { Text = message, // 设置消息文本 AutoSize = true, // 自动调整标签大小以适应文本 Location = new System.Drawing.Point(20, 20), // 设置标签位置 }; // 初始化第一个选项按钮并设置其属性 btnOption1 = new Button { Text = button1Text, // 设置按钮文本 DialogResult = DialogResult.OK, // 设置按钮的对话框结果为 OK Location = new System.Drawing.Point(20, 80),