I am doing an app that adds a certain character for each selected line if you click the button. for example "//" in each line in a Richtextbox and colored the text into red, it is like the function of comment out in visual studio
i tried this but it did'nt work
private void toolStripButton1_Click(object sender, EventArgs e)
{
int firstCharPosition = richTextBox1.GetFirstCharIndexOfCurrentLine();
int lineNumber = richTextBox1.GetLineFromCharIndex(firstCharPosition);
int lastCharPosition = richTextBox1.GetFirstCharIndexFromLine(lineNumber + 1);
if (richTextBox1.SelectionLength > 0)
{
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "//" + richTextBox1.SelectedText.ToString();
}
else
{
richTextBox1.Select(firstCharPosition, lastCharPosition - firstCharPosition);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "//" + richTextBox1.SelectedText.ToString();
}
}
guys please help me thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…