By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

RichText Problems

P: n/a
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!
Dec 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 28 Dec 2007 11:54:29 -0800, Soulless <dg*******@gmail.comwrote:
[...]
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
Dec 28 '07 #2

P: n/a
On Dec 28, 2:02*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Fri, 28 Dec 2007 11:54:29 -0800, Soulless <dgmsal...@gmail.comwrote:
[...]
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.
Dec 28 '07 #3

P: n/a
On Fri, 28 Dec 2007 12:27:58 -0800, Soulless <dg*******@gmail.comwrote:
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
Dec 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.