Hi @Anonymous ,
According to your description, I think you are using C++/CLI, so I spent some time to realize your needs.
In the following code, MyForm
is the main form and MyForm1
is the secondary form.
MyForm.h
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
public:
property System::Windows::Forms::TextBox ^
txt1 {
System::Windows::Forms::TextBox ^ get() {
return textBox1;
} void set(System::Windows::Forms::TextBox ^ value) {
textBox1 = value;
}
}
public
: property System::Windows::Forms::TextBox ^
txt2 {
System::Windows::Forms::TextBox ^ get() {
return textBox2;
} void set(System::Windows::Forms::TextBox ^ value) {
textBox2 = value;
}
}
In this example, I added a button to the secondary form to pass values to the TextBox
.
MyForm1.h
private:
System::Void button1_Click(System::Object ^ sender,
System::EventArgs ^ e) {
MyForm ^ form1 = (MyForm^)Application::OpenForms["MyForm"];
form1->txt1->Text = "test1";
form1->txt2->Text = "test2";
MyForm.cpp
#include "MyForm.h"
#include "MyForm1.h"
using namespace Project50;
using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
int main(array<System::String ^> ^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyForm form;
MyForm1 form2;
form2.Show();
Application::Run(% form);
return 0;
}
Best regards,
Elya
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.