Is it possible to Show a MessageBox or Something simular to a MessageBox that by it self will show for about 2 seconds so you doesn´t have to press OK.

So what happens is that a "messageBox" will appear for about 2 seconds and the by itself dissapear ?
(A messageBox without an "OK" button)

MessageBox::Show("Text here");
10 Years
Discussion Span
Last Post by Radical Edward

Yes, create your own message box using a dialog box, then set up a timer event to kick off in 2 seconds. In the timer event handler destroy the dialog box.


Thanks. I am not sure how to do any of these I think.
A dialog box is not the same as a MessageBox ?

A timer Event, is this the TimerClass that I can find in the Toolbox ?

So I beleive the first Step is to put code inside a buttoncontrol that will show a
Dialog Box ? I am not sure how to do this ?

Yes, create your own message box using a dialog box, then set up a timer event to kick off in 2 seconds. In the timer event handler destroy the dialog box.


they are all win32 api functions. Here is a tutorial that will get you started with writing windows programs. After doing all the exercises in that tutorial you will know how to create a dialog box. Then it will be pretty easy to add SetTimer() to setup a timer event and the event handler function, and KillTimer() to stop it.


From what Edward has seen, you're using Windows Forms and not Win32. Without any of the bells and whistles of the standard message box, it's pretty simple to write your own message box dialog that closes after a set time. Here's a bare bones example:

#pragma once

using namespace System;
using namespace System::Timers;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;

namespace FormsScratch {
  public ref class EdMessageBox: public Form {
    System::ComponentModel::Container^ components;
    System::Windows::Forms::Label^ labelMessage;
    System::Windows::Forms::Button^ buttonCancel;
    System::Windows::Forms::Button^ buttonOK;

    // Ed added this to close the form
    // after a set number of milliseconds
    System::Timers::Timer^ _timer;
    EdMessageBox(String^ message, int milliseconds)

      _timer = gcnew System::Timers::Timer();
      _timer->Interval = milliseconds;
      _timer->Elapsed += gcnew ElapsedEventHandler(
        this, &EdMessageBox::_timer_Tick);
      if (components)
        delete components;
    // Visual Studio added generated code here, but Edward will paste it
    // in another code block so it doesn't distract from the meat of the form

    System::Void EdMessageBox_Load(Object^ sender, EventArgs^ e)
      _timer->Enabled = true;

    System::Void _timer_Tick(Object^ sender, ElapsedEventArgs^ e)
      // The timer ticks only once, and then
      // the dialog closes with a status that
      // can't be reached through the buttons
      _timer->Enabled = false;
      DialogResult = ::DialogResult::Abort;

    System::Void buttonOK_Click(Object^ sender, EventArgs^ e)
      DialogResult = ::DialogResult::OK;

    System::Void buttonCancel_Click(Object^ sender, EventArgs^ e) 
      DialogResult = ::DialogResult::Cancel;

Here is the designer generated code for the form:

#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
      this->labelMessage = (gcnew System::Windows::Forms::Label());
      this->buttonCancel = (gcnew System::Windows::Forms::Button());
      this->buttonOK = (gcnew System::Windows::Forms::Button());
      // labelMessage
      this->labelMessage->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
        | System::Windows::Forms::AnchorStyles::Left) 
        | System::Windows::Forms::AnchorStyles::Right));
      this->labelMessage->Location = System::Drawing::Point(-1, -1);
      this->labelMessage->Name = L"labelMessage";
      this->labelMessage->Size = System::Drawing::Size(512, 150);
      this->labelMessage->TabIndex = 0;
      // buttonCancel
      this->buttonCancel->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right));
      this->buttonCancel->Location = System::Drawing::Point(424, 162);
      this->buttonCancel->Name = L"buttonCancel";
      this->buttonCancel->Size = System::Drawing::Size(75, 23);
      this->buttonCancel->TabIndex = 1;
      this->buttonCancel->Text = L"Cancel";
      this->buttonCancel->UseVisualStyleBackColor = true;
      this->buttonCancel->Click += gcnew System::EventHandler(this, &EdMessageBox::buttonCancel_Click);
      // buttonOK
      this->buttonOK->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right));
      this->buttonOK->Location = System::Drawing::Point(343, 162);
      this->buttonOK->Name = L"buttonOK";
      this->buttonOK->Size = System::Drawing::Size(75, 23);
      this->buttonOK->TabIndex = 2;
      this->buttonOK->Text = L"OK";
      this->buttonOK->UseVisualStyleBackColor = true;
      this->buttonOK->Click += gcnew System::EventHandler(this, &EdMessageBox::buttonOK_Click);
      // EdMessageBox
      this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
      this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
      this->ClientSize = System::Drawing::Size(511, 197);
      this->Name = L"EdMessageBox";
      this->Text = L"EdMessageBox";
      this->Load += gcnew System::EventHandler(this, &EdMessageBox::EdMessageBox_Load);

#pragma endregion
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.