How to call System::Windows::Forms::Controls "invoke" method?
-
I made a class myGroupbox to use SerialPort, and I'm trying to update a textbox from the serial port data. But the invoke function couldn't be used, the error message is "myGroupbox has no member invoke" here's my code
myGroupbox.h
#pragma once
using namespace System::Windows::Forms;
ref class myGroupbox
{
private: System::IO::Ports::SerialPort^ _serialPort;public: myGroupbox( System::IO::Ports::SerialPort^ serialPort ) { \_serialPort=serialPort; \_serialPort->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &myGroupbox::SerialPort\_DataReceived); }
private: System::Void SerialPort_DataReceived(System::Object^ sender,System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
uint16_t test = 0;test = \_serialPort->BytesToRead; if (test == 3U) { this->Invoke(gcnew EventHandler(this, &myGroupbox::ProcessReceived)); **// ERROR in this line, Invoke not found** } else { \_serialPort->DiscardInBuffer(); } } private: System::Void ProcessReceived(System::Object^ sender, System::EventArgs^ e) { //set textbox text }
}
-
I made a class myGroupbox to use SerialPort, and I'm trying to update a textbox from the serial port data. But the invoke function couldn't be used, the error message is "myGroupbox has no member invoke" here's my code
myGroupbox.h
#pragma once
using namespace System::Windows::Forms;
ref class myGroupbox
{
private: System::IO::Ports::SerialPort^ _serialPort;public: myGroupbox( System::IO::Ports::SerialPort^ serialPort ) { \_serialPort=serialPort; \_serialPort->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &myGroupbox::SerialPort\_DataReceived); }
private: System::Void SerialPort_DataReceived(System::Object^ sender,System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
uint16_t test = 0;test = \_serialPort->BytesToRead; if (test == 3U) { this->Invoke(gcnew EventHandler(this, &myGroupbox::ProcessReceived)); **// ERROR in this line, Invoke not found** } else { \_serialPort->DiscardInBuffer(); } } private: System::Void ProcessReceived(System::Object^ sender, System::EventArgs^ e) { //set textbox text }
}
Member 15150778 wrote:
the invoke function couldn't be used, the error message is "myGroupbox has no member invoke"
Well, you hadn't defined any Invoke() method in your myGroupbox class. Therefore you got this error message.
-
Member 15150778 wrote:
the invoke function couldn't be used, the error message is "myGroupbox has no member invoke"
Well, you hadn't defined any Invoke() method in your myGroupbox class. Therefore you got this error message.
Hello, I tried to copy my approach from the MyForm.cpp and it worked properly i.e. invoke wasn't define in MyForm.cpp but I could still call this invoke function since it's from System::Windows::Forms::Controls. But in my own class myGroupBox, it couldn't do the same. here's an snippet of MyForm.cpp that used the invoke and worked
using namespace System;
using namespace System::Windows::Forms;[STAThreadAttribute]
void main(array^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
myGUI ::MyForm form;
Application::Run(% form);
}namespace myGUI {
System::Void MyForm::serialPort1\_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) { if (serialPort1->IsOpen) { databufferA = serialPort1->ReadLine(); **this->Invoke(gcnew EventHandler(this, &MyForm::DisplayText));** } }
}
-
I made a class myGroupbox to use SerialPort, and I'm trying to update a textbox from the serial port data. But the invoke function couldn't be used, the error message is "myGroupbox has no member invoke" here's my code
myGroupbox.h
#pragma once
using namespace System::Windows::Forms;
ref class myGroupbox
{
private: System::IO::Ports::SerialPort^ _serialPort;public: myGroupbox( System::IO::Ports::SerialPort^ serialPort ) { \_serialPort=serialPort; \_serialPort->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &myGroupbox::SerialPort\_DataReceived); }
private: System::Void SerialPort_DataReceived(System::Object^ sender,System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
uint16_t test = 0;test = \_serialPort->BytesToRead; if (test == 3U) { this->Invoke(gcnew EventHandler(this, &myGroupbox::ProcessReceived)); **// ERROR in this line, Invoke not found** } else { \_serialPort->DiscardInBuffer(); } } private: System::Void ProcessReceived(System::Object^ sender, System::EventArgs^ e) { //set textbox text }
}
-
Hello, I tried to copy my approach from the MyForm.cpp and it worked properly i.e. invoke wasn't define in MyForm.cpp but I could still call this invoke function since it's from System::Windows::Forms::Controls. But in my own class myGroupBox, it couldn't do the same. here's an snippet of MyForm.cpp that used the invoke and worked
using namespace System;
using namespace System::Windows::Forms;[STAThreadAttribute]
void main(array^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
myGUI ::MyForm form;
Application::Run(% form);
}namespace myGUI {
System::Void MyForm::serialPort1\_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e) { if (serialPort1->IsOpen) { databufferA = serialPort1->ReadLine(); **this->Invoke(gcnew EventHandler(this, &MyForm::DisplayText));** } }
}
-
Yes, because you have still not declared an Invoke method in your class, and your class is not a child of
System.Windows.Forms.Control
.Hello, thank you very much for your help! I am able to compile after following your suggestion. I will test if this method works and update if this is the final solution. Thanks again!
myGroupbox.h
#pragma once
using namespace System::Windows::Forms;
ref class myGroupbox: public System::Windows::Forms::Control
{
private: System::IO::Ports::SerialPort^ _serialPort;.
.
.