Czyli co mam to zrobić w ten sposób?
MyFormControl::MyFormControl()
{
myButton = gcnew Button;
myListBox = gcnew ListBox;
myButton->Location = Point(72,160);
myButton->Size = System::Drawing::Size( 152, 32 );
myButton->TabIndex = 1;
myButton->Text = "Add items in list box";
myButton->Click += gcnew EventHandler( this, &MyFormControl::Button_Click );
myListBox->Location = Point(48,32);
myListBox->Name = "myListBox";
myListBox->Size = System::Drawing::Size( 200, 95 );
myListBox->TabIndex = 2;
ClientSize = System::Drawing::Size( 292, 273 );
array<Control^>^formControls = {myListBox,myButton};
Controls->AddRange( formControls );
Text = " 'Control_Invoke' example ";
myDelegate = gcnew AddListItem( this, &MyFormControl::AddListItemMethod );
}
void MyFormControl::AddListItemMethod( String^ myString )
{
myListBox->Items->Add( myString );
}
void MyFormControl::Button_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
myThread = gcnew Thread( gcnew ThreadStart( this, &MyFormControl::ThreadFunction ) );
myThread->Start();
}
void MyFormControl::ThreadFunction()
{
MyThreadClass^ myThreadClassObject = gcnew MyThreadClass( this );
myThreadClassObject->Run();
}