当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - RichTextBox, Insert into the first row and keep the alignments

问题描述:

Roulette program. I've got a RichTextBox (History) what shows the last numbers,

aligned by their colors. The newest number takes place at the end of the list.

The Click event:

private void numbers_Click(object sender, System.EventArgs e)

{

Button numbers = (Button)sender;

switch (numbers.BackColor.Name)

{

case "Green":

History.SelectionColor = Color.LightGreen;

History.SelectionAlignment = HorizontalAlignment.Center;

break;

case "Red":

History.SelectionColor = Color.Red;

History.SelectionAlignment = HorizontalAlignment.Left;

break;

case "Black":

History.SelectionColor = Color.LightGray;

History.SelectionAlignment = HorizontalAlignment.Right;

break;

}

History.AppendText(numbers.Text + "\n");

}

Works properly. Now I would like to reverse the order. But can't figure out the solution.

What I tried:

History.Text = History.Text.Insert(0, numbers.Text + "\n");

This aligns every number to the same side depend on what was the first and only shows one of the required colors after I selected all of the texts and clicked one button.

History.Text = History.Text.Insert(0, History.SelectedText = numbers.Text + "\n");

Again, aligns every number to the same side, but now every numbers' colors changing with the new number's color.

分享给朋友:
您可能感兴趣的文章:
随机阅读: