Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual C++: Unable to invoke method from another class
    primarykey
    data
    text
    <p>Please have a look at the following code</p> <p><strong>Form1.h</strong></p> <pre><code>#pragma once #include "Clicker.h" namespace TestWindowProject { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// &lt;summary&gt; /// Summary for Form1 /// &lt;/summary&gt; public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// &lt;summary&gt; /// Clean up any resources being used. /// &lt;/summary&gt; ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; protected: private: /// &lt;summary&gt; /// Required designer variable. /// &lt;/summary&gt; System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; void InitializeComponent(void) { this-&gt;button1 = (gcnew System::Windows::Forms::Button()); this-&gt;SuspendLayout(); // // button1 // this-&gt;button1-&gt;Location = System::Drawing::Point(115, 91); this-&gt;button1-&gt;Name = L"button1"; this-&gt;button1-&gt;Size = System::Drawing::Size(75, 23); this-&gt;button1-&gt;TabIndex = 0; this-&gt;button1-&gt;Text = L"button1"; this-&gt;button1-&gt;UseVisualStyleBackColor = true; this-&gt;button1-&gt;Click += gcnew System::EventHandler(this, &amp;Form1::button1_Click); // // Form1 // this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13); this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this-&gt;ClientSize = System::Drawing::Size(284, 262); this-&gt;Controls-&gt;Add(this-&gt;button1); this-&gt;Name = L"Form1"; this-&gt;Text = L"Form1"; this-&gt;ResumeLayout(false); } #pragma endregion private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Clicker c; c.click(); } }; } </code></pre> <p><strong>Clicker.h</strong></p> <pre><code>#pragma once ref class Clicker { public: Clicker(void); void click(); }; </code></pre> <p>Clicker.cpp</p> <pre><code>#include "StdAfx.h" #include "Clicker.h" #include &lt;iostream&gt; using namespace std; Clicker::Clicker(void) { } void Clicker::click() { cout &lt;&lt; "Clicked" &lt;&lt; endl; } </code></pre> <p>This is my first GUI application in C++. When I click the button, nothing is happening! I can't see anything in the output! Why is that? Am I doing something wrong? please help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload