注册 登录
编程论坛 C语言论坛

求助: 自定义 MessageBoxButtons 。

追梦人zmrghy 发布于 2022-08-05 21:01, 1246 次点击
只有本站会员才能查看附件,请 登录


只有本站会员才能查看附件,请 登录


如何把 ‘是’‘否’‘取消’  改成   ‘继续闯关’‘再来一遍’‘退出游戏’。。。。


只有本站会员才能查看附件,请 登录


倒霉的MessageBoxButtons 只有这6种按钮组合方式呀
4 回复
#2
追梦人zmrghy2022-08-05 22:24
只有本站会员才能查看附件,请 登录


只有本站会员才能查看附件,请 登录


只有本站会员才能查看附件,请 登录
#3
apull2022-08-05 22:51
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录


程序代码:

#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编辑过]

#4
追梦人zmrghy2022-08-05 23:18
回复 3楼 apull
是俩个winform窗体吗?
如何是winform窗体,如何去掉,右上角的 最小化、最大化 只留下一个关闭按钮呀?
#5
apull2022-08-05 23:19
添加一个Form当做Messagebox用。
 this->MaximizeBox = false; //最大化
 this->MinimizeBox = false; //最小化
 this->TopMost = true; //窗口置顶
1