C# RichTextBox jumps to bottom after RichTextBox.TextAlignment changed.

  • Thread starter Thread starter Milwaukee Broad
  • Start date Start date
M

Milwaukee Broad

Guest
I'm writing a C# WinForms app using a RichTextBox. When I open an .rtf file that contains text and images and try to change any selected image or text's alignment to HorizontalAlignment.Left, HorizontalAlignment.Center or HorizontalAlignment.Right, the RichTextFile performs the operation correctly, but then the cursor jumps down to the bottom of the RichtTextBox. Here's the code for the SelectionAlignment ops...

private void TsbtnAlignLeft_Click(object sender, EventArgs e)
{
foreach (RichTextBox rtb in spltMain.Panel2.Controls.OfType<RichTextBox>())
{
rtb.SelectionAlignment = HorizontalAlignment.Left;
}
}

private void TsbtnAlignCenter_Click(object sender, EventArgs e)
{
foreach (RichTextBox rtb in spltMain.Panel2.Controls.OfType<RichTextBox>())
{
rtb.SelectionAlignment = HorizontalAlignment.Center;
}
}

private void TsbtnAlignRight_Click(object sender, EventArgs e)
{
foreach (RichTextBox rtb in spltMain.Panel2.Controls.OfType<RichTextBox>())
{
rtb.SelectionAlignment = HorizontalAlignment.Right;
}
}

The problem occurs whether I'm working with a block of text or an image and it only happens with .rtf file I open, rather than new .rtf files I create. I want the RichTextBox to stay exactly where it is. How can I prevent the jump to the bottom?

Continue reading...
 
Back
Top