Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8278391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:59:35+00:00 2026-06-08T08:59:35+00:00

I am learning Visual C++ and have come across quite the stumbling block on

  • 0

I am learning Visual C++ and have come across quite the stumbling block on Day 1. I am attempting to make a simple ‘Hello World’ application using the Form template in Visual C++ 2010.

The solution created Form1.h, resource.h, stdafx.h, AssemblyInfo.cpp, helloworld.cpp, and stdafx.cpp. I added a button and a label to Form1 and was able to make it so that when the button is clicked the label changed text to “Hello World” from within Form1.h. I would like to do this from Form1.cpp though, so I stripped the code from the header. I currently have the following code:

Form1.cpp

#include "stdafx.h"
#include "stdio.h"
#include "Form1.h"

using namespace helloworld;


helloworld::Void testButton_Click(System::Object^  sender, System::EventArgs^  e) {
    helloworld::Form1::label1->Text = "Test";
}

Form1.h

#pragma once

namespace helloworld {

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

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  testButton;
    public: System::Windows::Forms::Label^  label1;
    protected: 

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>testButton
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->testButton = (gcnew System::Windows::Forms::Button());
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->SuspendLayout();
            // 
            // testButton
            // 
            this->testButton->Location = System::Drawing::Point(136, 159);
            this->testButton->Name = L"testButton";
            this->testButton->Size = System::Drawing::Size(75, 23);
            this->testButton->TabIndex = 0;
            this->testButton->Text = L"Test Button";
            this->testButton->UseVisualStyleBackColor = true;
            this->testButton->Click += gcnew System::EventHandler(this, &Form1::testButton_Click);
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Location = System::Drawing::Point(125, 100);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(35, 13);
            this->label1->TabIndex = 1;
            this->label1->Text = L"label1";
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(284, 262);
            this->Controls->Add(this->label1);
            this->Controls->Add(this->testButton);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void testButton_Click(System::Object^  sender, System::EventArgs^  e) ;
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
         }
    };
}

With this code I receive the following error:

error C2227: left of '->Text' must point to class/struct/union/generic type

From what I have found, that error means that the program doesn’t know what I am talking about with label1->Text. I would greatly appreciate any help that could be given to a Visual C++ newbie.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:59:36+00:00Added an answer on June 8, 2026 at 8:59 am

    The problem is in the following snippet:

    helloworld::Void testButton_Click(System::Object^  sender, System::EventArgs^  e) {
        helloworld::Form1::label1->Text = "Test";
    }
    

    helloworld::Form1 is the type of your form; it is not the actual instance. We use the this keyword to refer to the current object instance (most of the time the this keyword is optional). Another problem is helloworld::Void, which should be System::Void. You also need to replace testButton_Click with Form1::testButton_Click to show that this is a class method and not a free function. Your code should become:

    System::Void Form1::testButton_Click(System::Object^  sender, System::EventArgs^  e) {
        label1->Text = "Test";
    }
    

    Note: You should use C# when working with windows forms. C++/CLI is a mess of a language and the majority of people use C++/CLI only when combining managed with native code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning how to make a Visual Studio style properties grid. I have a
I am learning MVC with Razor and have a simple question (I think). I
I have visual studio 2010 only with no sql server.I use it for learning.Now
I am trying to get my hands on learning Visual force. I have an
I have Visual Studio 2010 with SP1 installed. I want to create a simple
I am just learning Blend/Silverlight/VS2010/.net/etc. I have a simple project that resides on a
I've started learning C++. Here's my simple problem. I have a code: int main()
I'm learning C++ and i have the eVT(eMbedded Visual Tools) installed in my computer,
I am learning visual basic .net and I am attempting to translate some java
I am learning Visual Studio 2010. I want to make a webpage that shows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.