0

Kind of new to c# GUI stuff

I am trying to output a message, a number to a textbox.

1 Button will calculate the number, then I want to write a message like " Number has been seen: "

I tried

Form2.resultBox.Text.Write("Number one has been seen: ", num0);

that doesn't work.

Also tried

Form2.resultBox += Console.WriteLine("Numer one has been seen: ", num0);

Im going to have about 16 of these messages

ideas?

1
  • 3
    resultBox.Text = "Number one has been seen: " + num0; Read the error messages; you'll see helpful advice. (In particular, what is wrong.) Commented Feb 6, 2012 at 22:17

3 Answers 3

2
Form2.resultBox.Text = "Number one has been seen: " + num0;
Sign up to request clarification or add additional context in comments.

Comments

1

To set the value of a TextBox, you should set a value on the Text property like so:

resultBox.Text = "Number one has been seen: " + num;

Comments

1

how about using the string.Format

Form2.resultBox.Text = string.Format("Number one has been seen: {0}", num0); 

eliminates having to use + sign

4 Comments

nothing wrong with + sign but in his case in my opinion it's better to pass params what if he wanted to have Nuber one has been seen: + num0 + Times..? wouldn't be easier to read {0}{1},num0,stringTimes for example..?
also think about in C# Immutable vs Mutable.. wouldn't it be better to use a StringBuilder to build Complex Strings vs using Operator overloading i.e string += some string(s) variable(s)
I agree with StringBuilder usage in that case, but I still prefer using + instead of {0}..
I'm not arguing with you on your preference Bojan but in the long run you will see that you will run into issues eventually when using operator overloading on complex strings .. you're approach is not incorrect.. I am just looking at best practices thats all.. cool..!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.