privatestaticvoidRtfTest(string inpath, string outpath) { // load rtf file RichTextBox rtf = new RichTextBox(); using (StreamReader sr = new StreamReader(inpath)) { rtf.Rtf = sr.ReadToEnd(); }
// add alert the begining of the rtf file rtf.SelectionStart = 0; rtf.SelectionLength = 1; string alert = "Alert!" + Environment.NewLine; rtf.SelectedText = alert + rtf.SelectedText; rtf.SelectionStart = 0; // length of new line in string is 2, but in rtf is 1, so we need to minus the line count rtf.SelectionLength = alert.Length - 1; rtf.SelectionColor = Color.Red; rtf.SelectionFont = new Font(rtf.SelectionFont, System.Drawing.FontStyle.Bold);