
程序代码:
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// MsgBox 摘要
/// </summary>
public ref class MsgBox : public System::Windows::Forms::Form
{
public:
MsgBox(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
System::Windows::Forms::DialogResult static Show(System::String^ caption, System::String^ text )
{
MsgBox^ msgbox = gcnew MsgBox();
msgbox->Text = caption;
msgbox->label1->Text = text;
msgbox->ShowDialog();
msgbox->~MsgBox();
return result;
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~MsgBox()
{
if (components)
{
delete components;
}
}
protected:
private:
System::Windows::Forms::DialogResult static result=::DialogResult::Ignore; //默认忽略,继续闯关
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Label^ label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container^ components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(12, 85);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 43);
this->button1->TabIndex = 0;
this->button1->Text = L"退出";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MsgBox::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(125, 85);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 43);
this->button2->TabIndex = 1;
this->button2->Text = L"重玩";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &MsgBox::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(236, 85);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 43);
this->button3->TabIndex = 2;
this->button3->Text = L"继续";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &MsgBox::button3_Click);
//
// label1
//
this->label1->Location = System::Drawing::Point(12, 24);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(299, 35);
this->label1->TabIndex = 3;
this->label1->Text = L"label1";
//
// MsgBox
//
this->ClientSize = System::Drawing::Size(338, 155);
this->Controls->Add(this->label1);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->KeyPreview = true;
this->MaximizeBox = false;
this->MinimizeBox = false;
this->Name = L"MsgBox";
this->ShowInTaskbar = false;
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
this->TopMost = true;
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
result = System::Windows::Forms::DialogResult::Abort;
this->Visible = false;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
result = System::Windows::Forms::DialogResult::Retry;
this->Visible = false;
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
result = System::Windows::Forms::DialogResult::Ignore;
this->Visible = false;
}
};

程序代码:
使用:
Form1.h中
#include "MsgBox.h"
private: System::Void pictureBox2_DoubleClick(System::Object^ sender, System::EventArgs^ e) {
System::Windows::Forms::DialogResult re=MsgBox::Show("过关!", "顺利过关,是否继续闯关?");
MessageBox::Show(re.ToString());
}
[此贴子已经被作者于2022-8-5 23:22编辑过]