Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox .SelectionFont problem or bug

Status
Not open for further replies.

snProgrammer

Programmer
Mar 21, 2005
3
FR
Hello,
I have the strangest problem working with a RichTextBox. I want the user to be able to select a chunk of text in a RTF box and make the text bold by clicking a button. This works fine the first time, but the second time not at all. In fact, when I did a step by step through the code, I found that the SelectionStart and SelectionLength values were both 0 for the second try. Here's the relevant code...

private void btn_Click(object sender, System.EventArgs e)
{
rtbInstrument.SelectionFont = new Font("Microsoft Sans Serif", (float)8.25, FontStyle.Bold);
}

Any ideas? Thanks in advance.

Sue
 
Does the selection remain after the first time?

(i.e. if you put in a dummy line after the trbInstrument. line, what is the selection start and length at that point, is the application of the new font resetting it?

K
 
Hi,
The selection is gone as soon as I set the font. Small detail...this is only a problem if the RichTextBox is databound.

Thanks!
Sue
 
The only other thing I can think of then is to store the start and length values, set the font, then re-set the start and length values?

HTH

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top