C++ simple GUI conversion

Doing a C++ GUI for extra credit, I want the user to input his/her age and output a result depending on the result.

1
2
3
4
5
6
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	if (comboBox1->Text == "0")
	{
		label2->Text = System::Convert::ToString(("You are still a baby"));
		label2->Text = System::Convert::ToString(("Keep on developing"));
	}


The problem is only "Keep on developing" is showing whenever 0 is inputted how do I show both "You are still a baby" & "Keep on developing" when 0 is inputted?

Also any suggestions on GUI tutorials and guide?
1
2
3
4
5
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	if (comboBox1->Text == "0")
	{
		label2->Text = System::Convert::ToString(("You are still a baby. Keep on developing."));
	}
this looks more like c#
but anyways, why have 2 lines of string returns of the same caller, where you can have them combined into 1
theyre both inside the "0" anyways

only "keep on developing" is showing because it's the last duplicate line so it replaces whatever is on top of it
Last edited on
Do your strings have concatenation/append operation?

In C++
1
2
3
4
5
std::string dummy; // empty string, ""
if ( cond ) dummy += "baby"; // append
dummy += "keep"; // always append

GUIcrap = dummy; // show complete string 
What if I want to show it on different text lines? for example.

You are still a baby // 1st line
Keep on developing// 2nd line

Basically, what I'm looking for, the best way I think my beginner brain can say is, when using a GUI is there an endl; version?

@jvlinh I'm gonna be honest our prof. is not going to teach us GUI and I'm doing it with mostly the help of this website and a lot of youtube. Also, I already did a normal C++ program for what I'm trying to do and it works just fine, the Windows Form is where I'm struggling to find tutorials and help

@keskiverto I'm sorry but I kinda don't understand the question? (we haven't discussed strings yet and I'm swimming blindly doing this GUI)

Not sure if I understand the problem correctly but you can display multiple line in a label like this:
 
  label1->Text = "Line 1" + Environment::NewLine + "Line 2";

Here are some tutorials about C++ / CLI: http://www.functionx.com/vccli/index.htm
https://stackoverflow.com/questions/1015766/difference-between-n-and-environment-newline

Aha, the Environment::NewLine and "\n" are both effectively string literal constants.
A "Hello\nDolly" has a newline in the middle.

The std::endl is send to a stream.
http://www.cplusplus.com/reference/ostream/endl/
It does write a newline character to a stream.

A GUI label is not a stream. It is an object that has a string member and the value of that member is rendered on display.

We assign a value to label1->Text. The value is an array of characters. We can have newline characters in the array.


It is possible that some GUI objects (like edit box) do not render multiline text content. One can get around that by having more label objects, but that might complicate layout management.
Thanks @Thomas1965 for showing an example it finally works

Also Thanks to @keskiverto for the explenation
Topic archived. No new replies allowed.