Changing Textbox from the cpp file

What I'm trying to do is change a textbox from the form1 from within the main '.cpp' file.

Basically, I want the text field to change on load. (Later it will be another reason).

Sorry if this is a dumb question. I'm a newbie.

I added the 2 lines in the Header file and changed the textbox from private to public. (guessing this isn't a good idea?)

Then I tried calling the change in the main function of the .cpp file.

Thank you so much for your help

.cpp file
#include "stdafx.h"
#include "Form1.h"

using namespace help;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());

//Added this.
Form1^ myform1 = gcnew Form1();
Form1::myForm1->MyBox->Text = L" ShowME! ";


return 0;
}


form1.h file

#pragma once

namespace help {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
static Form1^ myForm1; //Add this...
Form1(void)
{
InitializeComponent();
myForm1 = this; //added this...
//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::TextBox^ MyBox; //Changed To Public..
protected:

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->MyBox = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// MyBox
//
this->MyBox->Location = System::Drawing::Point(20, 57);
this->MyBox->Name = L"MyBox";
this->MyBox->Size = System::Drawing::Size(247, 20);
this->MyBox->TabIndex = 0;
this->MyBox->TextChanged += gcnew System::EventHandler(this, &Form1::MyBox_TextChanged);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->MyBox);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void MyBox_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}
BTW. I know I could update it from the form1 file but thats not what I need. :-)
Topic archived. No new replies allowed.