Solved

Launching a form from a form

Posted on 2011-03-08
8
450 Views
Last Modified: 2013-11-20
I have an application developed under Microsoft Visual Studio .NET 2003 (Visual C++) with two forms, Form1 and Form2.

When I click a button on Form1 (Button2) I want to hide Form1 and show Form2. But how ?
(Yes, I am a newbie on this topic.. :-( ).


The code generated by MS Visual Studio .NET 2003 (Visual C++) is:


      private: System::Void button2_Click(System::Object *  sender, System::EventArgs *  e)
                   {                  
//                  Put some code in here to launch Form2.

                   }
0
Comment
Question by:toyboy61
  • 5
  • 3
8 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 150 total points
ID: 35072740
Form2^ frm = new Form2();
this->Hide();
frm->ShowWindow();



ps.  .Net code is not MFC - the two are rather different languages.
0
 

Author Comment

by:toyboy61
ID: 35072858
private: System::Void button2_Click(System::Object *  sender, System::EventArgs *  e)
                   {                  
                         Form2^ frm = new Form2();
                         this->Hide();
                         frm->ShowWindow();
                   }

When trying to compile this source code I get the following errors:

Form1.h(104) : error C2143: syntax error : missing ';' before '^'
Form1.h(106) : error C2065: 'frm' : undeclared identifier
Form1.h(106) : error C2227: left of '->ShowWindow' must point to class/struct/union
 type is ''unknown-type''
C:\Programfiler\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinUser.h(3691) : error C2365: 'ShowWindow' : redefinition; previous definition was a 'formerly unknown identifier'

What have I done wrong here ? :-(

0
 

Assisted Solution

by:toyboy61
toyboy61 earned 0 total points
ID: 35073981
The following code compiled and run without errors.

                        Form2 * md1=new Form2();
                        md1->Activate();
                        md1->Show();


0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35079607
But that isn't C++ .net code - hw did it even compile?
0
 

Author Comment

by:toyboy61
ID: 35081538
I'm a newbie. I use Microsoft Visual Studio .NET 2003 IDE with Visual C++.
Your code (which of course is C++.net-code) did not compile (see error messages in an earlier posting), but my code snippet did compile and - surprisingly - it runs as well.

I started by choosing "Visual C++ Projects" and then "Windows Forms Application" as template. This template should be "A project for creating an application with a Windows user interface using Managed Extensions for C++.".  So maybe I'm not using .NET-code using this template at all - or.. ???
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35081889
>>MS Visual Studio .NET 2003

Hmmm, is it using the older syntax?  Microsoft made some changes to C++.net very early on.  Be careful, you might be writing code that you would have difficulty porting to a newer version of visual studio.
0
 

Author Comment

by:toyboy61
ID: 35084432
It seems so. And I no intention of upgrading to a new version of Visual Studio now. I only want to make this program work on the Windows platform. Maybe I'll port it to Java later on.. :-))
0
 

Author Closing Comment

by:toyboy61
ID: 35126359
No additional comments.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question