Solved

Launching a form from a form

Posted on 2011-03-08
8
441 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
Comment Utility
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
Comment Utility
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
Comment Utility
The following code compiled and run without errors.

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


0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
But that isn't C++ .net code - hw did it even compile?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:toyboy61
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
No additional comments.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now