Click here to Skip to main content
15,921,884 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionSerialization problem Pin
roshihans20-May-10 21:05
roshihans20-May-10 21:05 
Questiona little help ,find a word from text Pin
Gilbertu19-May-10 10:43
Gilbertu19-May-10 10:43 
AnswerRe: a little help ,find a word from text Pin
Luc Pattyn19-May-10 14:05
sitebuilderLuc Pattyn19-May-10 14:05 
AnswerRe: a little help ,find a word from text Pin
T210215-Jun-10 21:26
T210215-Jun-10 21:26 
QuestionGet the button click event from another form Pin
rikterveen18-May-10 20:46
rikterveen18-May-10 20:46 
GeneralRe: Get the button click event from another form Pin
Andreoli Carlo18-May-10 21:56
professionalAndreoli Carlo18-May-10 21:56 
GeneralRe: Get the button click event from another form Pin
rikterveen20-May-10 7:16
rikterveen20-May-10 7:16 
AnswerRe: Get the button click event from another form [modified] Pin
Andreoli Carlo20-May-10 23:14
professionalAndreoli Carlo20-May-10 23:14 
so....here we are:

in form 1 substitute:
private: System::Void testbutton_click(System::Object^  sender, System::EventArgs^  e) {
				 testlabel->Text = "new form open";

				 Form2^ popup = gcnew Form2();
				 popup->ShowDialog();
			 }

	private: void raised_event (System::Object^  sender, System::EventArgs^  e)
			 {
				 /* Get the text from the textbox on the other form */
				 Form2^ popup = gcnew Form2();
				 testlabel->Text = popup->textbox->Text;
			 }
	};

// susbstitute with.....

private: 
	Form2^ popup;
	void testbutton_click(System::Object^  sender, System::EventArgs^  e) {
				 testlabel->Text = "new form open";

				 popup = gcnew Form2();
				 popup->button_send->Click += gcnew EventHandler(this, &Form1::raised_event);
				 popup->ShowDialog();
			 }

	void raised_event (System::Object^  sender, System::EventArgs^  e)
			 {
				 testlabel->Text = popup->textbox->Text;
			 }


i'm pretty sure you'll understand my changes.

Maybe it would be better to use delegates....i'll write you some code for that

// form 1/////////////////////////////////////////////////////////
#pragma once
#include "Form2.h"

namespace delete1 {

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

	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
		}

	protected:
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: 
		void testbutton_click(System::Object^  sender, System::EventArgs^  e) {
			testlabel->Text = "new form open";

			Form2^ popup = gcnew Form2();
			popup->myPersonalDelegateCl += gcnew Form2::myPersonalDelegate(this,&Form1::raised_from_delegate);
			popup->ShowDialog();
		}
		void raised_from_delegate (String ^txt)
		{
			this->testlabel->Text=txt;
		}
		System::Windows::Forms::Button^  testbutton;
		System::Windows::Forms::Label^  testlabel;
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		void InitializeComponent(void)
		{
			this->testbutton = (gcnew System::Windows::Forms::Button());
			this->testlabel = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();

			/* Testbutton */
			this->testbutton->Location = System::Drawing::Point(12, 326);
			this->testbutton->Name = L"button_test";
			this->testbutton->Size = System::Drawing::Size(75, 23);
			this->testbutton->TabIndex = 0;
			this->testbutton->Text = L"Test";
			this->testbutton->UseVisualStyleBackColor = true;
			this->testbutton->Click += gcnew System::EventHandler(this, &Form1::testbutton_click);
			// 
			// testlabel
			// 
			this->testlabel->AutoSize = true;
			this->testlabel->Location = System::Drawing::Point(9, 19);
			this->testlabel->Name = L"label_test";
			this->testlabel->Size = System::Drawing::Size(35, 13);
			this->testlabel->TabIndex = 1;
			this->testlabel->Text = L"";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(382, 361);
			this->Controls->Add(this->testlabel);
			this->Controls->Add(this->testbutton);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();
		}
#pragma endregion
	};
}

// form 2/////////////////////////////////////////////////////////
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace Test2 {
	public ref class Form2 : public System::Windows::Forms::Form
	{
	public:
		Form2(void)
		{
			InitializeComponent();
		}
		delegate void myPersonalDelegate(String ^txt);
		myPersonalDelegate^ myPersonalDelegateCl;
	protected:
		~Form2()
		{
			if (components)
			{
				delete components;
			}
		}
	private:
		void Form2_Load(System::Object^  sender, System::EventArgs^  e) {
			 textbox->Text = "hoi";
		}
		void button_send_Click(System::Object^  sender, System::EventArgs^  e) {
			 this->myPersonalDelegateCl(this->textbox->Text);
		}
		System::Windows::Forms::RichTextBox^  textbox;
		System::Windows::Forms::Button^  button_send;
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		void InitializeComponent(void)
		{
			this->textbox = (gcnew System::Windows::Forms::RichTextBox());
			this->button_send = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// textbox
			// 
			this->textbox->Location = System::Drawing::Point(12, 12);
			this->textbox->Name = L"textbox";
			this->textbox->Size = System::Drawing::Size(268, 147);
			this->textbox->TabIndex = 0;
			this->textbox->Text = L"";
			// 
			// button_send
			// 
			this->button_send->Location = System::Drawing::Point(12, 165);
			this->button_send->Name = L"button_send";
			this->button_send->Size = System::Drawing::Size(75, 23);
			this->button_send->TabIndex = 1;
			this->button_send->Text = L"Send";
			this->button_send->UseVisualStyleBackColor = true;
			this->button_send->Click += gcnew System::EventHandler(this, &Form2::button_send_Click);
			// 
			// Form2
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(292, 198);
			this->Controls->Add(this->button_send);
			this->Controls->Add(this->textbox);
			this->Name = L"Form2";
			this->Text = L"Form2";
			this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
			this->ResumeLayout(false);
		}
#pragma endregion
	};
}


ps1 alway split code in .h and in .cpp
ps2 don't ever write personalized code between #pragma region Windows Form Designer generated code and #pragma endregion

modified on Friday, May 21, 2010 5:27 AM

GeneralRe: Get the button click event from another form Pin
rikterveen27-May-10 20:44
rikterveen27-May-10 20:44 
GeneralRe: Get the button click event from another form Pin
Andreoli Carlo31-May-10 12:01
professionalAndreoli Carlo31-May-10 12:01 
AnswerRe: Get the button click event from another form Pin
voo doo125-Jun-10 6:24
voo doo125-Jun-10 6:24 
Questionnot able to built project in release mode Pin
sharada veena17-May-10 19:26
sharada veena17-May-10 19:26 
Questionhelp vc++.net Pin
Gilbertu17-May-10 0:22
Gilbertu17-May-10 0:22 
AnswerRe: help vc++.net Pin
Richard MacCutchan17-May-10 1:26
mveRichard MacCutchan17-May-10 1:26 
Question[] symbol appears in string when reading from / writing to file Pin
KlaasVersteeg16-May-10 23:57
KlaasVersteeg16-May-10 23:57 
QuestionSizeof out of scope? Pin
Xpnctoc8-May-10 6:39
Xpnctoc8-May-10 6:39 
AnswerRe: Sizeof out of scope? Pin
Michel Godfroid8-May-10 8:48
Michel Godfroid8-May-10 8:48 
AnswerRe: Sizeof out of scope? Pin
Richard MacCutchan8-May-10 8:59
mveRichard MacCutchan8-May-10 8:59 
AnswerRe: Sizeof out of scope? Pin
Xpnctoc8-May-10 17:54
Xpnctoc8-May-10 17:54 
GeneralRe: Sizeof out of scope? Pin
Michel Godfroid8-May-10 20:15
Michel Godfroid8-May-10 20:15 
GeneralRe: Sizeof out of scope? Pin
Xpnctoc9-May-10 12:18
Xpnctoc9-May-10 12:18 
GeneralRe: Sizeof out of scope? Pin
Richard MacCutchan9-May-10 22:12
mveRichard MacCutchan9-May-10 22:12 
GeneralRe: Sizeof out of scope? Pin
Xpnctoc10-May-10 4:30
Xpnctoc10-May-10 4:30 
GeneralRe: Sizeof out of scope? Pin
Richard MacCutchan10-May-10 5:15
mveRichard MacCutchan10-May-10 5:15 
GeneralRe: Sizeof out of scope? Pin
Xpnctoc10-May-10 5:47
Xpnctoc10-May-10 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.