ninja_aya 发表于 2015-11-5 08:40:00

Section的删除和添加



在这个模板中我想实现两个功能,一个是删除第二章,一个是在最后插入一个新的章节,但是删除第二章的时候会留空白,请问这里有直接删除真个section的方法吗?我的代码如下:
private void 删除章节ToolStripMenuItem_Click(object sender, EventArgs e)
      {
            List<int> k = new List<int>();
            k.Add(2);
            foreach (int i in k)
            {
                Section s = _textControl.Sections;
                RemoveApplication(s.Start, s.Start + s.Length);
                _textControl.Sections.Select();
                _textControl.Selection.Text = "";
            }
      }
      /// <summary>
      /// 删除不可编辑域
      /// </summary>
      /// <param name="tx"></param>
      /// <param name="start"></param>
      /// <param name="end"></param>
      private void RemoveApplication(int start, int end)
      {
            foreach (ApplicationField af in _textControl.ApplicationFields)
            {
                if (af.Start >= start &amp;&amp; af.Start < end)
                {
                  _textControl.ApplicationFields.Remove(af);
                }
            }
      }


另外一个功能我想插入一个章节,但是如果碰到tx中最后一个是ApplicationField的时候就没法添加了,请问如何解决?代码如下:
int start = _textControl.Sections.Start + _textControl.Sections.Length;
            _textControl.Selection.Start = start;
            _textControl.Selection.Length = 1;
            if (_textControl.Sections.Add(SectionBreakKind.BeginAtNewPage))
            {
                _textControl.Selection.Start = _textControl.Sections.Start+1;
                _textControl.Selection.Length = 1;
                ApplicationField af = CreateMergeField("chapter_tb_4", "新增的章节");
            }

Alice 发表于 2015-11-5 12:11:00

回复 1楼ninja_aya的帖子

非常感谢您的反馈。
您的示例我们已经收到了,测试后给您反馈。

ninja_aya 发表于 2015-12-1 13:52:00

请问什么时候能有答复

iceman 发表于 2015-12-1 18:20:00

回复 3楼ninja_aya的帖子

请尝试通过以下代码移除 Section:

private void RemoveAllSections()
{
    TXTextControl.SectionCollection.SectionEnumerator sectionEnum = textControl1.Sections.GetEnumerator();
    int sectionCounter = textControl1.Sections.Count;

    sectionEnum.Reset();
    sectionEnum.MoveNext();
    for (int i = 0; i &lt; sectionCounter; i++)
    {
      TXTextControl.Section curSection = (TXTextControl.Section)sectionEnum.Current;

      if (curSection.Number == 1)
      {
            sectionEnum.MoveNext();
            continue;
      }

      textControl1.Selection.Start = curSection.Start - 2;
      textControl1.Selection.Length = 1;
      textControl1.Selection.Text = &quot;&quot;;
    }
}
页: [1]
查看完整版本: Section的删除和添加