User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,052 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,464 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 285 | Replies: 6
Reply
Join Date: Feb 2008
Posts: 445
Reputation: Jennifer84 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro in Training

Get String^ From Another Forms textBox1

  #1  
Jul 8th, 2008
I have Form1 and Form2 in my project. On Form1 I open Form2 like this:
Form2^form2 = gcnew Form2;
form2->Show();

In the Form2:s LoadEvent I use this code so this Form2 will be Active/Shown even that I click on Form1:
private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) 
{
    Form2::TopMost::set(true);
}

Now is my question this. If I have a textBox1 on Form2 with a written text inside. How can it be possible reach this text from a button on Form1.

Usually you could have written like this if the textBox was on Form1 in this case:
String^ GetText = textBox1->Text;
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Get String^ From Another Forms textBox1

  #2  
Jul 8th, 2008
I do recall reading one of your threads that asked basically the same question and received a good answer (an answer which would solve your current similar problem). Perhaps you should take the time to learn the concepts of the answers you're given rather than just slapping the example code into your project and hacking it into submission.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Feb 2008
Posts: 445
Reputation: Jennifer84 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro in Training

Re: Get String^ From Another Forms textBox1

  #3  
Jul 8th, 2008
I am not sure if you could meen that I can get the String from Form2, beginning with the
FormClass and then the textBox like this.
I can find the richTextBox1 as a member and I have declared the richTextBox as public on Form2:
If I write the first example. The compiler says.
left of '->Text' must point to class/struct/union/generic type
#include "Form2.h"
String^ GetText = Form2::richTextBox1->Text;




Originally Posted by Narue View Post
I do recall reading one of your threads that asked basically the same question and received a good answer (an answer which would solve your current similar problem). Perhaps you should take the time to learn the concepts of the answers you're given rather than just slapping the example code into your project and hacking it into submission.
Last edited by Jennifer84 : Jul 8th, 2008 at 1:50 pm.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Get String^ From Another Forms textBox1

  #4  
Jul 8th, 2008
>I am not sure if you could meen that I can get the String from Form2
What I mean is that you need to engage your brain around here, because you've been told how to pass data between two forms before: use properties or events. Generally, if you ask the same question multiple times, we assume you're nothing but a mindless leech looking for quick answers, and nobody will want to help you.

>I have declared the richTextBox as public on Form2
That's about the worst possible solution. If you have to make private data public, you're doing something wrong.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Feb 2008
Posts: 445
Reputation: Jennifer84 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro in Training

Re: Get String^ From Another Forms textBox1

  #5  
Jul 8th, 2008
>> we assume you're nothing but a mindless leech looking for quick answers

I beleive it is important that I mention something here. I am not looking for quick answers.
If I have passed data between forms before I would be happy to know what question that was because I have left out this question for 2 months. The only things I do is to read and write to files.
This is the only way I communicate between the Forms, passing strings and text right now through textfiles.
For the moment I dont know any other way.
Perheps I have done this or something simular in a way I haven´t thought of ofcourse.
I will check the properties and events now and it could be a good way as you say to experiment around and see if I can solve it myself. I will do this.
One way I know I can do is to to use the event Text_Changed that writes all contents to a file each time you write something and then I can read this file.

j


Originally Posted by Narue View Post
>I am not sure if you could meen that I can get the String from Form2
What I mean is that you need to engage your brain around here, because you've been told how to pass data between two forms before: use properties or events. Generally, if you ask the same question multiple times, we assume you're nothing but a mindless leech looking for quick answers, and nobody will want to help you.

>I have declared the richTextBox as public on Form2
That's about the worst possible solution. If you have to make private data public, you're doing something wrong.
Last edited by Jennifer84 : Jul 8th, 2008 at 2:40 pm.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,065
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Get String^ From Another Forms textBox1

  #6  
Jul 8th, 2008
>I am not looking for quick answers.
So slow ones will do?

>If I have passed data between forms before I would be happy to know what
>question that was because I have left out this question for 2 months.
I remember reading a thread where a public property in one form allowed another form to get private data. You're one of the few people who asks about C++/CLI on this forum, and I'm pretty sure it was you, though I could be wrong.

>This is the only way I communicate between the Forms,
>passing strings and text right now through textfiles.
Read up on properties. I can only mention it so many times before I get tired of my advice being ignored.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Feb 2008
Posts: 445
Reputation: Jennifer84 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro in Training

Re: Get String^ From Another Forms textBox1

  #7  
Jul 8th, 2008
Thanks Narue, I will read the properties and also my previous posts to see if I can find anything. I dont want to be to sure myself either and really understand its tiring to answer the same questions.

I found one thread where I did ask how to declare a managed vector to be reached from two buttoncontrols. I would fill the vector from one buttoncontrol on the form and the second buttoncontrol on the same form would read the contents that the vector stored.
I am not really sure about the meening with private and public so I just wrote public like below.
So I had to declare it in managed because it had to be declared ´outside´ the buttoncode.
This I remember I asked but this perheps wasn´t the one.

public: System::Collections::Generic::List<double> OneVector;


Originally Posted by Narue View Post
>I am not looking for quick answers.
So slow ones will do?

>If I have passed data between forms before I would be happy to know what
>question that was because I have left out this question for 2 months.
I remember reading a thread where a public property in one form allowed another form to get private data. You're one of the few people who asks about C++/CLI on this forum, and I'm pretty sure it was you, though I could be wrong.

>This is the only way I communicate between the Forms,
>passing strings and text right now through textfiles.
Read up on properties. I can only mention it so many times before I get tired of my advice being ignored.
Last edited by Jennifer84 : Jul 8th, 2008 at 4:18 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:50 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC