Cookieman BSOD Kernel Dump Senior Analyst Joined Jun 21, 2012 Posts 124 Location Lincoln (UK) Dec 5, 2012 #1 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.
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.
niemiro Senior Administrator, Windows Update Expert Staff member Joined Mar 2, 2012 Posts 8,769 Location District 12 Dec 5, 2012 #2 Would Code: richTextBox1.Text = "Your Text"; do the job? Do I understand you correctly? However, you should read this page also: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.text.aspx In particular, the Remarks section on Rich Text, and Multiline text boxes. Richard
Would Code: richTextBox1.Text = "Your Text"; do the job? Do I understand you correctly? However, you should read this page also: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.text.aspx In particular, the Remarks section on Rich Text, and Multiline text boxes. Richard
Cookieman BSOD Kernel Dump Senior Analyst Joined Jun 21, 2012 Posts 124 Location Lincoln (UK) Dec 5, 2012 #3 As simple as that! thanks Richard, I must check more on the mdsn site... :thumbsup2:
niemiro Senior Administrator, Windows Update Expert Staff member Joined Mar 2, 2012 Posts 8,769 Location District 12 Dec 5, 2012 #4 No problem, glad to help :)
AceInfinity Emeritus, Contributor Joined Feb 21, 2012 Posts 1,728 Location Canada Dec 8, 2012 #5 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.
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.
AceInfinity Emeritus, Contributor Joined Feb 21, 2012 Posts 1,728 Location Canada Dec 9, 2012 #6 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.
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.
Cookieman BSOD Kernel Dump Senior Analyst Joined Jun 21, 2012 Posts 124 Location Lincoln (UK) Dec 9, 2012 #7 Thanks for the extra info Ace :thumbsup2: