Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Launching a form from a form

Posted on 2011-03-08
8
454 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 105
Auto build a project upon execution 20 87
scoreUp challenge 14 63
sumHeights2  challenge 7 114
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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