[SOLVED] Showing text in a rich text box on button press - Visual C#

Cookieman

BSOD Kernel Dump Senior Analyst
Joined
Jun 21, 2012
Posts
124
Location
Lincoln (UK)
Hi all - Just an quick and simple question for you experts here!

With recently upgrading to Visual Express 2012 and finding that the option for application console is no longer available I am now looking at forms and visual C#, I can display messages in a messagebox upon a button click without any problems but I cannot see how to display text to a rich textbox which I have placed on my form upon a button click.

Thanks.
 
If you want to append in C#, use += for short.

Code:
richTextBox1.Text += "appended value";

Much simpler/shorter than:
Code:
richTextBox1.Text = richTextBox1.Text + "appended value";

But both the same. In addition to +=, it should only really be used for smaller string concatenation. Larger string concatenation and you should be using the StringBuilder class because the ldstr operator isn't called more than once. What this means in terms of IL code is that you aren't rebuilding an entirely new string object to return a modified value. With the StringBuilder class you operate directly on the char data within the string and don't do anything more than what needs to be done to modify it's value, you aren't re-creating the entire string object over again.

Note that all these controls are actually still just Classes in the .NET framework. Therefore they have methods and properties like any other class, and a default constructor. The .Text, is actually a property that initializes the text field within that control.
 
On top of that, there's something called operator overloading, but that's somewhat of an advanced topic so I won't go there yet. This would change the functionality of how certain operators work on various types.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top