Hi Guys,
I have the following issue ...
I have a form with two richTextBoxes named
(01) richTextBox1
(02) richTextBox2
with some controls for selecting Font types (Arial, Courier, etc) and Font
size(s).
The text I enter in richTextBox1 gets copied (sent to) richTextBox2 upon
selecting a send button (provided in the form). Say, initially, I enter a
text (say, crazy)using a font (which is Courier, size = 10) and do a send.
The text "crazy" gets displayed in the richTextBox2 in the font that is
selected in the richTextBox1.
Now, I clear the richTextBox1 and enter a new text (say, language) using a
different font (which is Times New Roman, size 17) and do a send. Now the
text "language" gets appended to the earlier one "crazy" and gets displayed
as "crazylanguage". The displayed text is fine. The problem is with the
font.
I want the richTextBox2 to have the font of text "crazy" to be in the
Courier font with size = 10 and the newly appended text "language" to be in
the Times New Roman font with size = 17. But that is not what is happening.
The new text also, gets changed to the Courier font with size = 10.
I use the richTextBox2.Start position to calculate from where the new font
should be applicable and somehow it is not working. See the code below and
any help on this is appreciated.
PART OF THE CODE - BELOW
***************************
// Use the font selected from this in richTextBox2
// ***********************************
private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
fontUsed4CurrentText = richTextBox1.SelectionFont;
}
// On button send, copy the text from richTextBox1 to richTextBox2
// **************************************************
private void button1_Click(object sender, System.EventArgs e)
{
// Get the starting position for the new font to be applied
richTextBox2.SelectionStart += richTextBox2.TextLength;
// Get the length of the string to be copied
richTextBox2.SelectionLength = richTextBox1.TextLength;
// Set the font to be used for the copied/pasted text
richTextBox2.SelectionFont = fontUsed4CurrentText;
// The richTextBox1 text is appended to the existing text in
richTextBox2
richTextBox2.Text += richTextBox1.Text;
// The text entered in the richTextBox1 is cleared
// and the focus is set back to richTextBox1
richTextBox1.Text = "";
richTextBox1.Focus();
}
Expecting any help on this at the earliest. Thanks in advance. Let me know,
if you have any questions.
Regards,
Hariharan S