Try this to get started:
private void button4_Click(object sender, EventArgs e)
{
string selText = allText.Substring(richTextBox1.SelectionStart, richTextBox1.SelectionLength);
string[] rtfLines = richTextBox1.Lines;
string theLine;
for (int i = 0; i < rtfLines.Length; i++)
{
theLine = rtfLines[i];
if (selText.Contains(theLine))
{
rtfLines[i] = "\t" + theLine;
}
}
richTextBox1.Lines = rtfLines;
}
}
Note this only will add a tab at the start of lines that are fully contained in the current selection. If you have a partial selection in a line, that will be ignored.
Tabbing in a partial selection could be achieved, but that's another chapter: perhaps one you will write ?