473,503 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing data between forms C++

How to pass data between two forms?
I find in the Internet, but not found immplementation problem in Visual
Studio 2005 and C++ language.

Example:
I have a 2 forms: Form1 and Form2.

On a Form1 place label1 and button
First I declare: #include "Form2.h"

Next, I wrote Event button (show Form2):

Form2 ^frm2 = gcnew Form2();
frm2->Owner = this;
frm2->ShowDialog();

On a Form2 place textbox and button.
When I click button, change label1 on a Form1.

How to write this Event ?
(if I declare in source Form2: #include "Form1.h", compile with error!
)

In C# it's simple, but in C++ it's difficult.

Please help me

Oct 12 '06 #1
2 5617
qt***@o2.pl wrote:
On a Form2 place textbox and button.
When I click button, change label1 on a Form1.
The problem is that Form1.h includes Form2.h, and Form2.h includes
Form1.h, which is not possible. You should move the implementation of
the event handlers to the .cpp file. Form2.cpp should then include
Form1.h. I know that the designer puts the implementation in the header
file by default, but it's simply not possible to do what you want
without manually moving your implementation to where it belongs.

That is:

// into Form2.h:
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e);

// into Form2.cpp:
#include "Form1.h"

System::Void Form2::button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
form1->label1->Text = "whatever";
}

Tom
Oct 12 '06 #2
Tamas Demjen wrote:
qt***@o2.pl wrote:
>On a Form2 place textbox and button.
When I click button, change label1 on a Form1.


The problem is that Form1.h includes Form2.h, and Form2.h includes
Form1.h, which is not possible. You should move the implementation of
the event handlers to the .cpp file. Form2.cpp should then include
Form1.h. I know that the designer puts the implementation in the header
file by default, but it's simply not possible to do what you want
without manually moving your implementation to where it belongs.

That is:

// into Form2.h:
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e);

// into Form2.cpp:
#include "Form1.h"

System::Void Form2::button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
form1->label1->Text = "whatever";
}

Tom
And people wonder why C++/CLI is not catching on as a first class .net
language...

David Wilkinson
Oct 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3942
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
12
6507
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
2511
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
11
3460
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
4394
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
3241
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
5
2108
by: Rod | last post by:
I've written 2 ASP.NET applications (I've worked on one with a team and another by myself). In my ASP.NET pages, when saving data to a backend database I've done it by using the click event of a...
0
1467
by: Eric Sabine | last post by:
OK, I'm trying to further my understanding of threading. The code below I wrote as kind of a primer to myself and maybe a template that I could use in the future. What I tried to do was pass data...
2
2583
by: Carl Heller | last post by:
Working in VS2003, .Net 1.1 I'm working on a project where I compare data between two databases. This is a lengthy process, and very data intensive, so I decided to create a class, and thread...
1
2288
by: SteveDouglas | last post by:
Hi all, I am currently writing an application in VB.NET that has a lot of controls (treeviews/listviews/labels and so forth) that represent "things" that need to be draggable from place to place,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.