RichText Box Help pls...

  • Thread starter Thread starter Soulless
  • Start date Start date
S

Soulless

I have added a RTB to my form and found some code online:

rtb1.Rtf = @"{\rtf1\ansi \b Conversion Report\b0.}";

I want to be able to add lines to this box, with different fonts,
sizes, alignment, etc. But I am not sure what I can do with Rtf.

Obviously /b is for bold, but what else is there? Is there a link
with explanations on what I see above and more useful stuff?

Thanks!
 
This might start you off. Play around with the Method "Select", and
then look at the SelectionXXX properties, such as SelectionBackColor,
SelectionFont, SelectionColor, and so on.

Dom
 
This might start you off.  Play around with the Method "Select", and
then look at the SelectionXXX properties, such as SelectionBackColor,
SelectionFont, SelectionColor, and so on.

Dom







- Show quoted text -

Thanks guys, the problem I have is I am building the text as I go and
want to add bold text, normal text, etc etc... using selectedXXXX
requires the text to be selected, right?
 
I believe it is easiest to just get the string, and then use the usual
methods, SelectionXXX, etc, to dress it up.

Dom
 
Thanks guys, the problem I have is I am building the text as I go and
want to add bold text, normal text, etc etc... using selectedXXXX
requires the text to be selected, right?

You can save the current selection, select the text you want to format,
change the formatting as desired, and then restore the original selection.

Also, you can write some test code to just apply certain kinds of
formatting you're interested in, and then look at the RTF text that
results. In that way, you can figure out what RTF to apply yourself for
specific results, if you don't want to do the above to set formatting in
your actual application.

Pete
 
An easy way to get the RTF formatting codes you need is to create a Word
document with the items and formatting you need, and save it as RTF. You can
then examine the resulting as a text file.
-- Peter
Site:http://www.eggheadcafe.com
UnBlog:http://petesbloggerama.blogspot.com
MetaFinder:http://www.blogmetafinder.com









- Show quoted text -

I did managed to get it working with the following ... but the problem
is my right alignment on the first part does not work and I do not
know why. The Centre below works, but not the first alignment... any
ideas?

rtb1.Text = "Conversion Report";
rtb1.SelectionStart = 0;
rtb1.SelectionLength = rtb1.Text.Length;
rtb1.SelectionColor = Color.Blue;
rtb1.SelectionAlignment = HorizontalAlignment.Right;
rtb1.SelectionFont = new Font("Microsoft Sans Serif", 16,
FontStyle.Bold);


rtb1.Text += Environment.NewLine + Environment.NewLine;


int liLen = rtb1.Text.Length;
string lsText = "Works?";
rtb1.Text += lsText;
rtb1.SelectionStart = liLen;
rtb1.SelectionLength = lsText.Length;
rtb1.SelectionColor = Color.Black;
rtb1.SelectionAlignment = HorizontalAlignment.Center;
rtb1.SelectionFont = new Font("Microsoft Sans Serif", 10,
FontStyle.Regular);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top