RichText Problems

S

Soulless

Hi, I am going crazy trying to resolve a stupid issue. I have a RTB
control and created a method to accept a string and (hopefully) set
the font and size and alignment... Here is the method:

private void AddToRTFReport(string asText, object aoColor,
string asFont,object aoFontStyle, int aiSize, object aoAlignment)
{
int liLen = rtb1.Text.Length;
if (liLen <= 0)
{
rtb1.Text = asText;
rtb1.SelectionStart = 0;
rtb1.SelectionLength = rtb1.Text.Length;
}
else
{
rtb1.Text += asText;
rtb1.SelectionStart = liLen;
rtb1.SelectionLength = asText.Length;
}

rtb1.SelectionColor = (Color)aoColor;
rtb1.SelectionAlignment =
(HorizontalAlignment)aoAlignment;
rtb1.SelectionFont = new Font(asFont, aiSize,
(FontStyle)aoFontStyle);

}

I call my method like this:
AddToRTFReport("Some Text", Color.Black, "Microsoft Sans Serif",
FontStyle.Bold, 10, HorizontalAlignment.Center);

The problem is, if I call it using bold, 16 pt and then call it again
using regular 10 point, everything displays as bold 16pt. It is
making me crazy. Can you see what I may be doing wrong??

Thanks!
 
P

Peter Duniho

[...]
The problem is, if I call it using bold, 16 pt and then call it again
using regular 10 point, everything displays as bold 16pt. It is
making me crazy. Can you see what I may be doing wrong??

I'm not seeing anything immediately apparent to me. Maybe someone else
can solve this via code inspection.

But: what do you see when you step through the code? What is the
selection just before you set the selection formatting properties? Did it
get set to the text you expected it to?

Pete
 
S

Soulless

[...]
The problem is, if I call it using bold, 16 pt and then call it again
using regular 10 point, everything displays as bold 16pt.  It is
making me crazy.  Can you see what I may be doing wrong??

I'm not seeing anything immediately apparent to me.  Maybe someone else  
can solve this via code inspection.

But: what do you see when you step through the code?  What is the  
selection just before you set the selection formatting properties?  Did it  
get set to the text you expected it to?

Pete

When I walk through it, it all looks fine... I can see the appropriate
font, but it is not reflected on the Richtext control.

I am putting newlines in as well to work with a totally different line
of text. don't know if that is causing an issue.
 
P

Peter Duniho

When I walk through it, it all looks fine... I can see the appropriate
font, but it is not reflected on the Richtext control.

But what's the selection for the control at the moment that you set the
SelectionFont (for example)?
I am putting newlines in as well to work with a totally different line
of text. don't know if that is causing an issue.

I don't think it should, but I suppose you could try it without them.

For best help, you should post a concise but complete sample of code that
reliably reproduces the problem. I haven't had a chance to try the code
you posted, but if the problem isn't reproducible with any random Forms
application using that code, no one will be able to look at the behavior
directly without a complete sample from you.

Pete
 

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

Top