943,840 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2204
  • C++ RSS
Jul 8th, 2008
0

Get String^ From Another Forms textBox1

Expand Post »
I have Form1 and Form2 in my project. On Form1 I open Form2 like this:
C++ Syntax (Toggle Plain Text)
  1. Form2^form2 = gcnew Form2;
  2. form2->Show();

In the Form2:s LoadEvent I use this code so this Form2 will be Active/Shown even that I click on Form1:
C++ Syntax (Toggle Plain Text)
  1. private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e)
  2. {
  3. Form2::TopMost::set(true);
  4. }

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

Usually you could have written like this if the textBox was on Form1 in this case:
C++ Syntax (Toggle Plain Text)
  1. String^ GetText = textBox1->Text;
Similar Threads
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Jul 8th, 2008
1

Re: Get String^ From Another Forms textBox1

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 8th, 2008
0

Re: Get String^ From Another Forms textBox1

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
C++ Syntax (Toggle Plain Text)
  1. #include "Form2.h"
  2. String^ GetText = Form2::richTextBox1->Text;




Click to Expand / Collapse  Quote originally posted by Narue ...
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 2:50 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Jul 8th, 2008
1

Re: Get String^ From Another Forms textBox1

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 8th, 2008
0

Re: Get String^ From Another Forms textBox1

>> 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


Click to Expand / Collapse  Quote originally posted by Narue ...
>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 3:40 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008
Jul 8th, 2008
1

Re: Get String^ From Another Forms textBox1

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 8th, 2008
0

Re: Get String^ From Another Forms textBox1

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;


Click to Expand / Collapse  Quote originally posted by Narue ...
>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 5:18 pm.
Reputation Points: 10
Solved Threads: 1
Posting Pro
Jennifer84 is offline Offline
563 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Just a few errors :(
Next Thread in C++ Forum Timeline: Need help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC