I am doing windows forms application in C++, using visual studio 2005.

I could reach Form2 from Form1 by clicking a "log-in" button in Form1, after fill in the name in a textbox.
Then I would like to show the log-in name in Form2 somewhere. I have got a class for the name and other things called the "Profile".

I thought I could make a label first (label2) and try to change the code governing it to show the log-in name.

Codes for label2:

Profile abc;
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(105, 26);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(41, 12);
this->label2->TabIndex = 1;
this->label2->Text = abc.getId(id);

The red parts are my changes.
The last line used to be "this->label2->Text = L"label2";" , showing "label2" in Form2.

But my change is not working and got error. I wonder how to fix it.


The following is my class for "Profile":

using namespace std;
class Profile
{
private:
	char id[20]; 
    int win; 
    int lose; 
public:
    Profile(); 
    Profile(char *Id, int win, int lose); 
    ~Profile(); 
    void getId(char *Id); 
    int getWin(); 
    int  getLose(); 
    void setId(char *Id); 
    void setWin (int Win);
	void setLose (int Lose);
    int read_Record(char *FName, char *Id);
public:
    int update_Record(char *FName);
};

Thanks !

There are two easy ways:

1. Use ShowMessage( char * )
This puts up a little dialogue box with your text and an OK button. It causes your application to pause until the user clicks OK.

2. If time is an issue, then call AllocConsole() somewhere at the beginning of your program (in main() or in your form's constructor, etc). Thereafter you can use cin and cout as usual.

Hope this helps.

There are two easy ways:

1. Use ShowMessage( char * )
This puts up a little dialogue box with your text and an OK button. It causes your application to pause until the user clicks OK.

2. If time is an issue, then call AllocConsole() somewhere at the beginning of your program (in main() or in your form's constructor, etc). Thereafter you can use cin and cout as usual.

Hope this helps.

I know about ShowMessage. But that's not what I want to do

I would like to change how LABEL2 shows because I want to make the log-in name show on the Form2 all the time.

Actually Form2 is the game interface I am dealing with and I need to show the log-in person's name on the form all the time. Is it possible to do that?

The red parts are my changes.
The last line used to be "this->label2->Text = L"label2";" , showing "label2" in Form2.
But my change is not working and got error. I wonder how to fix it.

What is the error(s) you are getting? Might be helpful to post the compiler error(s) ...

I'm sorry ... I didn't pay enough attention to the question.

You should set the label's Caption property, not Text.

Hope this helps.

What is the error(s) you are getting? Might be helpful to post the compiler error(s) ...

C++ CodeDOM parser error: Line: 108, Column: 34 --- Member getId not found in class Profile
Hide

at Microsoft.VisualC.CppCodeParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)

I do not need to compile.
I just change the code in "Form2.h" and click back to "Form2 deign" tab then the error shows.

But the Profile class is ok since I have used it in Form1. After click the "log-in" button on Form1, Form2 shows.
I have added "#include "Profile.h" at the beginning but there is no difference whether I add it or not

I'm sorry ... I didn't pay enough attention to the question.

You should set the label's Caption property, not Text.

Hope this helps.

If I just add a button in a Form, the code for the button is:

this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(273, 26);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(41, 12);
this->label1->TabIndex = 11;
this->label1->Text = L"label1";

So the default action is to generate these codes to create a button.
I ckecked the properties but there is no item "Caption".
How to write it in the " .h" tab to make a label show something that is not fixed but depending on what you type in in the previous form?

You seem to have a void getId() function, shouldn't that function return a pointer to the id member of the class?

You might then use it like

this->label->Text = gcnew System::String(abc.getId());

assuming that you have the instance abc of the Profile class available.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.