Hey, everyone. Today I'm going to show you how to do Hello world with a label, and a button.
First off. The button is going to change the text of the label to say "Hello World".
Ok lets get started. First create a new program called Hello world, Make sure its a Win32 form Application. As seen here.
Next, Your going to drag a Button and a Label onto the Form, Change the Button Text and form1 Text to Hello world in the Properties. Leave label1 text label1.
Re Arange everything on the Form1 design to the way you want.
Next, Double click the button you should see :
Now scroll up a bit, until you see
Code:
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(48, 92);
this->label1->Name = L"label2";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"label1";
Now that you see
Code:
this->label1->Text = L"label1";
Change the
to
The reason we did that instead of in the properties is because, It's hard to see the label after the text is changed to Nothing, So Make sure it was where you wanted it!
Next, Double click the button again, you should see
Code:
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
Don't worry this isn't hard at all,
Now Put this code into it.
Code:
This->label1->text = "Hello World";
So it will look like
Now Press F5, to Run the program you should get no errors!
Now, Press the button and watch the label text change to Hello world!
Now thats all, for now~
Credits to me for tut.