private void MarkTOCParagraphs() { // mark all paragraphs that will be indexed ProgressBar.Value = 0; Paragraphs myPars = new Paragraphs(tx); ArrayList pars = myPars.GetParagraphs(); ProgressBar.Maximum = pars.Count; foreach (Paragraph curPar in pars) { ProgressBar.PerformStep(); ProgressBar.Refresh(); int styleCount = 1; foreach (string style in MatchList) { if (curPar.Style == style) { TXTextControl.DocumentTarget newTarget = new TXTextControl.DocumentTarget("target," + styleCount.ToString() + "," + style + "," + curPar.Text + "," + curPar.Start.ToString()); tx.Select(curPar.Start, 0); tx.DocumentTargets.Add(newTarget); } styleCount++; } } }
// this method removes an existing TOC in the document public void Remove() { ProgressBar.Value = 0; int startValue = 0; int endValue = 0; TXTextControl.DocumentTargetCollection.TextFieldEnumerator targetEnum = tx.DocumentTargets.GetEnumerator(); int targetCounter = tx.DocumentTargets.Count; ProgressBar.Maximum = targetCounter; targetEnum.Reset(); targetEnum.MoveNext(); for (int i = 0; i < targetCounter; i++) { ProgressBar.PerformStep(); ProgressBar.Refresh(); targetEnum.Reset(); targetEnum.MoveNext(); TXTextControl.DocumentTarget curTarget = (TXTextControl.DocumentTarget)targetEnum.Current; if (curTarget.TargetName == "TOC_Start") { startValue = curTarget.Start - 1; tx.DocumentTargets.Remove(curTarget); } if (curTarget.TargetName == "TOC_End") { endValue = curTarget.Start - 1; tx.DocumentTargets.Remove(curTarget); } if (curTarget.TargetName.StartsWith("target,") == true) { tx.DocumentTargets.Remove(curTarget); } } tx.Select(startValue, endValue - startValue); tx.Selection.Text = ""; }