[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Launching a form from a form

Posted on 2011-03-08
8
Medium Priority
?
470 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 45

Accepted Solution

by:
AndyAinscow earned 600 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 45

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 45

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

834 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