Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to call System::Windows::Forms::Controls "invoke" method?

How to call System::Windows::Forms::Controls "invoke" method?

Scheduled Pinned Locked Moved Managed C++/CLI
helptutorialquestionannouncement
6 Posts 3 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15150778
    wrote on last edited by
    #1

    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
    
    }
    

    }

    V L 2 Replies Last reply
    0
    • M Member_15150778

      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
      
      }
      

      }

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • V Victor Nijegorodov

        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.

        M Offline
        M Offline
        Member_15150778
        wrote on last edited by
        #3

        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));**
        
        	}
        }
        

        }

        L 1 Reply Last reply
        0
        • M Member_15150778

          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
          
          }
          

          }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You cannot call a method that you have not declared. Your class contains only two methods: SerialPort_DataReceived

          1 Reply Last reply
          0
          • M Member_15150778

            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));**
            
            	}
            }
            

            }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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.

            M 1 Reply Last reply
            0
            • L Lost User

              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.

              M Offline
              M Offline
              Member_15150778
              wrote on last edited by
              #6

              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;

              .
              .
              .

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups