Passing/Keeping/Returning String From Form/Dialog - C++ /CLI

I am trying to pass a reference to a String to a Form that shows a Dialog for user input and then pass the input String back out. I have followed several other questions on this and just can not get the syntax to work.

The form/dialog that I call looks like:

public ref class SingleStringUI : public System::Windows::Forms::Form
public:  System::String^ tUserInput;


    SingleStringUI(System::String ^% UserInput)
        tUserInput = UserInput;

private: System::Void SingleStringOKButton_Click(System::Object^  sender, System::EventArgs^  e) {
         tUserInput = gcnew ystem::String(this->SingleStringTextBox->Text);

The caller looks like:

        SV8::SingleStringUI^ TestMatch;
        System::String^ UserInput;

        TestMatch = (gcnew SV8::SingleStringUI(UserInput));

However, when I run this, the string entered into the TextBox is not returned to the caller. Other examples I have seen indicate that the problem is when I store a local copy in tUserInput. Any help on getting a copy of the String out of the TextBox appreciated.


Re-assigning tUserInput in SingleStringOKButton_Click does not change UserInput because tUserInput is just a handle to UserInput and not a tracking reference to the handle. The only opportunity to change UserInput was in the SingleStringUI constructor. You could provide an accessor to get the string from the TextBox instead.

Need Your Help

Java binary tree add method over writes root

java recursion binary-tree

I am trying to write a binary tree and the add method is continually overwriting the root of the tree. I have two methods a recursive add method that takes in a String and a Node and then a regular...

Enum bitfield container class

c++ enums bit-fields bitflags

Im trying to write a small class to better understand bit flags in c++. But something isnt working out. It prints the wrong values. Where is the problem? Have I misunderstood how to add flags? Or c...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.