Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

VC++.Net DialogBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
foreman - 06 Mar 2005 03:46 GMT
Hello Everybody:

     I am trying out DialogBox, and I have been trying to press the
OK Button on the dialogbox hoping I can receive the OK DialogResult
to Main Form. Below is my OK button click event handler code on
AboutBox Dialogbox:

DialogResult = DialogResult::OK;

It can also dismiss the dialogbox and return OK "Ideally".

But I can't get the OK value from the main form, instead I keep get
the
None value in DialogResult. Anybody helps me please.
===============================================
Form1.h
===============================================
#pragma once
#include "AboutBox.h"

namespace testform3
{
    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>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to
change the
    ///          'Resource File Name' property for the managed resource
compiler tool
    ///          associated with all .resx files this class depends on.
Otherwise,
    ///          the designers will not be able to interact properly with
localized
    ///          resources associated with this form.
    /// </summary>
    public __gc class Form1 : public System::Windows::Forms::Form
    {   
    public:
        Form1(void)
        {
            InitializeComponent();
            ///combo1->SelectedIndex = 0;
        }
 
    protected:
        void Dispose(Boolean disposing)
        {
            if (disposing && components)
            {
                components->Dispose();
            }
            __super::Dispose(disposing);
        }
    private: System::Windows::Forms::MainMenu *  mainMenu1;
    private: System::Windows::Forms::MenuItem *  menuItem1;
    private: System::Windows::Forms::MenuItem *  aboutMenuitem;
    private: System::Windows::Forms::MenuItem *  exitMenuitem;
    private: System::Windows::Forms::MenuItem *  menuItem2;
    private: System::Windows::Forms::ContextMenu *  contextMenu1;
    private: System::Windows::Forms::MenuItem *  menuItem3;
    private: System::Windows::Forms::MenuItem *  menuItem4;
    private: System::Windows::Forms::MenuItem *  menuItem5;
    private: System::Windows::Forms::Button *  button1;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container * components;

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->mainMenu1 = new System::Windows::Forms::MainMenu();
            this->menuItem1 = new System::Windows::Forms::MenuItem();
            this->aboutMenuitem = new System::Windows::Forms::MenuItem();
            this->menuItem2 = new System::Windows::Forms::MenuItem();
            this->exitMenuitem = new System::Windows::Forms::MenuItem();
            this->contextMenu1 = new System::Windows::Forms::ContextMenu();
            this->menuItem3 = new System::Windows::Forms::MenuItem();
            this->menuItem4 = new System::Windows::Forms::MenuItem();
            this->menuItem5 = new System::Windows::Forms::MenuItem();
            this->button1 = new System::Windows::Forms::Button();
            this->SuspendLayout();
            //
            // mainMenu1
            //
            System::Windows::Forms::MenuItem* __mcTemp__1[] = new
System::Windows::Forms::MenuItem*[1];
            __mcTemp__1[0] = this->menuItem1;
            this->mainMenu1->MenuItems->AddRange(__mcTemp__1);
            //
            // menuItem1
            //
            this->menuItem1->Index = 0;
            System::Windows::Forms::MenuItem* __mcTemp__2[] = new
System::Windows::Forms::MenuItem*[3];
            __mcTemp__2[0] = this->aboutMenuitem;
            __mcTemp__2[1] = this->menuItem2;
            __mcTemp__2[2] = this->exitMenuitem;
            this->menuItem1->MenuItems->AddRange(__mcTemp__2);
            this->menuItem1->Text = S"&File";
            //
            // aboutMenuitem
            //
            this->aboutMenuitem->Index = 0;
            this->aboutMenuitem->Text = S"&About";
            this->aboutMenuitem->Click += new System::EventHandler(this,
aboutMenuitem_Click);
            //
            // menuItem2
            //
            this->menuItem2->Index = 1;
            this->menuItem2->Text = S"-";
            //
            // exitMenuitem
            //
            this->exitMenuitem->Index = 2;
            this->exitMenuitem->Text = S"E&xit";
            this->exitMenuitem->Click += new System::EventHandler(this,
exitMenuitem_Click);
            //
            // contextMenu1
            //
            System::Windows::Forms::MenuItem* __mcTemp__3[] = new
System::Windows::Forms::MenuItem*[3];
            __mcTemp__3[0] = this->menuItem3;
            __mcTemp__3[1] = this->menuItem4;
            __mcTemp__3[2] = this->menuItem5;
            this->contextMenu1->MenuItems->AddRange(__mcTemp__3);
            //
            // menuItem3
            //
            this->menuItem3->Index = 0;
            this->menuItem3->Text = S"item1";
            //
            // menuItem4
            //
            this->menuItem4->Index = 1;
            this->menuItem4->Text = S"item2";
            //
            // menuItem5
            //
            this->menuItem5->Index = 2;
            this->menuItem5->Text = S"item3";
            //
            // button1
            //
            this->button1->Location = System::Drawing::Point(72, 96);
            this->button1->Name = S"button1";
            this->button1->Size = System::Drawing::Size(120, 32);
            this->button1->TabIndex = 0;
            this->button1->Text = S"DialogResult";
            this->button1->Click += new System::EventHandler(this,
button1_Click);
            //
            // Form1
            //
            this->AutoScaleBaseSize = System::Drawing::Size(6, 18);
            this->ClientSize = System::Drawing::Size(720, 268);
            this->ContextMenu = this->contextMenu1;
            this->Controls->Add(this->button1);
            this->Menu = this->mainMenu1;
            this->Name = S"Form1";
            this->Text = S"Form1";
            this->ResumeLayout(false);

        }   
   

   

    private: System::Void aboutMenuitem_Click(System::Object *  sender,
System::EventArgs *  e)
            {
               
                AboutBox* box = new AboutBox();
                box->ShowDialog();
                MessageBox::Show(__box(this->DialogResult)->ToString());

            }

    private: System::Void exitMenuitem_Click(System::Object *  sender,
System::EventArgs *  e)
            {
                Application::Exit();

            }

private: System::Void button1_Click(System::Object *  sender,
System::EventArgs *  e)
        {
            MessageBox::Show(__box(this->DialogResult)->ToString());
        }

};
}

===============================================
Aboutbox.h
===============================================
#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;

namespace testform3
{
    /// <summary>
    /// Summary for AboutBox
    ///
    /// WARNING: If you change the name of this class, you will need to
change the
    ///          'Resource File Name' property for the managed resource
compiler tool
    ///          associated with all .resx files this class depends on.
Otherwise,
    ///          the designers will not be able to interact properly with
localized
    ///          resources associated with this form.
    /// </summary>
    public __gc class AboutBox : public System::Windows::Forms::Form
    {
    public:
        AboutBox(void)
        {
            InitializeComponent();
        }
       
    protected:
        void Dispose(Boolean disposing)
        {
            if (disposing && components)
            {
                components->Dispose();
            }
            __super::Dispose(disposing);
        }
    private: System::Windows::Forms::Label *  label1;
    private: System::Windows::Forms::Label *  label2;
    private: System::Windows::Forms::Button *  OKButton;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container* components;

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->label1 = new System::Windows::Forms::Label();
            this->label2 = new System::Windows::Forms::Label();
            this->OKButton = new System::Windows::Forms::Button();
            this->SuspendLayout();
            //
            // label1
            //
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(20, 30);
            this->label1->Name = S"label1";
            this->label1->Size = System::Drawing::Size(162, 21);
            this->label1->TabIndex = 0;
            this->label1->Text = S"The CPPForm Application";
            //
            // label2
            //
            this->label2->AutoSize = true;
            this->label2->Location = System::Drawing::Point(24, 56);
            this->label2->Name = S"label2";
            this->label2->Size = System::Drawing::Size(158, 21);
            this->label2->TabIndex = 1;
            this->label2->Text = S"Julian Templeman, 2001. ";
            //
            // OKButton
            //
            this->OKButton->DialogResult =
System::Windows::Forms::DialogResult::OK;
            this->OKButton->Location = System::Drawing::Point(112, 88);
            this->OKButton->Name = S"OKButton";
            this->OKButton->Size = System::Drawing::Size(40, 25);
            this->OKButton->TabIndex = 2;
            this->OKButton->Text = S"OK";
            //
            // AboutBox
            //
            this->AutoScaleBaseSize = System::Drawing::Size(6, 18);
            this->ClientSize = System::Drawing::Size(292, 118);
            this->Controls->Add(this->OKButton);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->label1);
            this->Name = S"AboutBox";
            this->Text = S"AboutBox";
            this->ResumeLayout(false);

        }       
    private: System::Void OKButton_Click(System::Object *  sender,
System::EventArgs *  e)
            {
                // Send back ’OK’ and close the form
                DialogResult = DialogResult::OK;
            }

    };
}
Tim Robinson - 06 Mar 2005 10:32 GMT
> Hello Everybody:
>
[quoted text clipped - 10 lines]
> the
> None value in DialogResult. Anybody helps me please.
[...]

The result is in the return value of ShowDialog. this->DialogResult would be
where you *set* the result if Form1 was modal.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.