I have a winform with bottoms and rtb.
the bottoms are : next and back.
with next I show wrapped statements. I want to remove the statements from last one to first when back clicked. because the statements have different font and color I cant use
richTextBox1.Text.Remove()
. because it changed color of remaining statements.
also there is a newline between each statements.
how can I remove statements correctly with back bottom?
here is my next bottom program :
private void button_woc2_MouseClick(object sender, MouseEventArgs e)
{
count++;
write_text(count,page);}
private void write_text(int count,int page)
{
if (page == 1)
{
switch (count)
{
case 1:
pictureBox2.Image = new Bitmap(_12.res.Resource4.p1);
pictureBox1.Image = new Bitmap(_12.res.Resource4.head1);
richTextBox1.Text = "example1";
richTextBox1.AppendText(Environment.NewLine);
back = true;
break;
case 2:
richTextBox1.Text += Environment.NewLine + "example2 ";
richTextBox1.AppendText(Environment.NewLine);
break;
case 3:
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.SelectionLength = 0;
richTextBox1.SelectionColor = Color.Black;
richTextBox1.AppendText(Environment.NewLine + "long statement example");
richTextBox1.SelectionColor = richTextBox1.ForeColor;
richTextBox1.SelectionFont = new Font("arial", 12);
richTextBox1.AppendText(Environment.NewLine);
break;
case 4:
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.SelectionLength = 0;
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.AppendText(Environment.NewLine + "example3");
richTextBox1.SelectionColor = richTextBox1.ForeColor;
richTextBox1.SelectionFont = new Font("arial", 12);
richTextBox1.AppendText(Environment.NewLine);
break;}
}
}
and this is my back bottom program :
private void button_woc1_Click(object sender, EventArgs e)
{
loop:
int start_index;
int charcount;
List<string> Lines = richTextBox1.Lines.ToList();
linecount = Lines.Count;
if (richTextBox1.Lines[linecount - 1] == "")
{
start_index =richTextBox1.GetFirstCharIndexFromLine(linecount-1 ) - 1;
charcount = 1;
richTextBox1.Select(start_index, charcount);
richTextBox1.SelectedText = " ";
goto loop;
}
else if (richTextBox1.Lines[linecount - 1] == " " ||richTextBox1.Lines[linecount - 1] == " ")
{
start_index = richTextBox1.GetFirstCharIndexFromLine(richTextBox1.GetLineFromCharIndex(richTextBox1.Text.Length-1)) ;
charcount =1;
richTextBox1.Select(start_index, charcount);
richTextBox1.SelectedText = null;
goto loop;
}
else
{
start_index = richTextBox1.GetFirstCharIndexFromLine(richTextBox1.GetLineFromCharIndex(richTextBox1.Text.Length));
charcount = richTextBox1.Lines[linecount - 1].Length;
richTextBox1.Select(start_index, charcount);
richTextBox1.SelectedText = " ";
count--;
}
}
}
the problem is with new lines, I cant delete them
thank you.
What I have tried:
I also tried :
richTextBox1.Select(start_index, charcount);
richTextBox1.SelectedText = " ";
but it didnt work correctly too.