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

  • SEARCH
  • Home
  • 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 8023099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:28:10+00:00 2026-06-04T22:28:10+00:00

I created this custom test class: #include Form1.h class Demo { public: void sayHello()

  • 0

I created this custom test class:

#include "Form1.h"

class Demo
{
public:
    void sayHello()
    {
        System::Windows::Forms::Form1->Text = "Hello Form!"; // does not work
        Form1->Text = "Hello Form!"; // does not work
        Form1.Text = "Hello Form!"; // does not work
    }
};

I essentially get this compiler error:

c:\users\pieter kubben\documents\visual studio 2010\projects\testclassref\testclassref\Demo.h(8): error C2065: 'Form1' : undeclared identifier
c:\users\pieter kubben\documents\visual studio 2010\projects\testclassref\testclassref\Demo.h(8): error C2227: left of '->Text' must point to class/struct/union/generic type

So I guess it does not see Form1. The other way around, so have the sayHello() function called when clicking the button in Form1, is no problem.

I noticed that my main() function (auto-generated by the IDE) contains this line:
Application::Run(gcnew Form1());

So it looks to me that Form1 has not yet been created when the compiler starts, although Form1.h does exist (of course).

How can I access Form1 elements from my custom class? E.g. change Form1.Text?

  • 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-04T22:28:14+00:00Added an answer on June 4, 2026 at 10:28 pm

    Create a global variable to hold your form object and alter the IDE generated to show the form
    like this

    Form1 frm=gvnew Form1();
    Application::Run(frm);
    

    Now frm is the referecne fo the form1 class and you can access it to access the Form1 class members. If you want to access frm object outside of the Main function then declare a global variable and access it.

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

Sidebar

Related Questions

I want to create a Model: public class TestModel { Microdata(Data = data-test=this is
I created a custom module for Orchard following this wonderful guide . I have
I have created a custom tag that looks like this: def textField = {
I have created a custom function and I am getting this error. I dont
Can a custom event be created for any object method? To do this do
This post will be heavy on images. I have created a custom ArrayAdapter and
Currently, I've created a class with ~30 properties to be set. This is done
I created a custom assembly to convert RTF to plain text and it works
I'm just learning about custom controls in C# (window forms) I've created the below
I've created a custom ViewGroup based on a LinearLayout. ClearableEditText.java package test.todolist; import android.content.Context;

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.