找回密码
 立即注册

QQ登录

只需一步,快速开始

KingMan

中级会员

68

主题

148

帖子

554

积分

中级会员

积分
554
KingMan
中级会员   /  发表于:2017-5-23 18:53  /   查看:5903  /  回复:11
本帖最后由 KingMan 于 2017-5-23 19:51 编辑

我现在要实现的功能是清掉内容前面的空行。
但是在调试的过程中发现一个问题,不知道这个问题是我没有搞清楚还是这个控件确实是存在这个问题。

        /// <summary>
        /// 清除内容前面的空行
        /// 注意,但是如果空行后面紧跟表格对象,则清除不了,该控件存在这个问题
        /// </summary>
        /// <returns></returns>
        public int ClearBeginLineFeed()
        {
            int iPostion = 0;
            LineCollection pLines = textControl1.Lines;
            foreach (Line pNextLine in pLines)
            {
                String sText = pNextLine.Text;
                if (sText.Trim().Length > 0)
                    break;
                //如果文本中含有回车符 “\r\n    ” 或 “     \r\n” 而Tab键 ”\t“ 为单字符
                if (sText.Contains("\r\n"))
                    iPostion += 1;
                sText = sText.Replace("\r\n", "");
                iPostion += sText.Length;
            }
            if (iPostion > 0)
            {
                //注意,在测试过程中发现在TXControl .NET 23.0版本中,如果Selection.Start = 0 则会定位到表格后面,导致清除不了
                textControl1.Selection.Start = 0;
                textControl1.Selection.Length = iPostion;
                textControl1.Selection.Text = "";
            }
            return iPostion;
        }

11 个回复

正序浏览
gw0506
超级版主   /  发表于:2017-5-26 18:20:44
12#
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             //sets the focus to the control
  4.             textControl1.Focus();

  5.             //makes control characters visible
  6.             textControl1.ControlChars = true;

  7.             //enters a control character into the Text Control
  8.             textControl1.Text = "\r\n";
  9.             
  10.             textControl1.Selection.Start = 1;
  11.             textControl1.Tables.Add(1, 3,100);
  12.             
  13.             textControl1.Selection.Start = 1;

  14.             //creates TextChar at the first position which is the control character
  15.             TXTextControl.TextChar controlChar = textControl1.TextChars[textControl1.Selection.Start];

  16.             //removes the control character
  17.             textControl1.TextChars.Remove(controlChar);
  18.         }
复制代码
回复 使用道具 举报
gw0506
超级版主   /  发表于:2017-5-25 14:10:20
11#
实在没办法了,发厂商了,有回复了告诉你。
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-5-24 19:46:47
10#
gw0506 发表于 2017-5-24 19:01
那就换个思路,用Lines。

这个方法试过啦,
1.Lines中没有删除Line指定行方法
2.Line中的Text 是只读
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-5-24 19:46:44
9#
gw0506 发表于 2017-5-24 19:01
那就换个思路,用Lines。

这个方法试过啦,
1.Lines中没有删除Line指定行方法
2.Line中的Text 是只读
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-5-24 19:46:40
8#
gw0506 发表于 2017-5-24 19:01
那就换个思路,用Lines。

这个方法试过啦,
1.Lines中没有删除Line指定行方法
2.Line中的Text 是只读
回复 使用道具 举报
gw0506
超级版主   /  发表于:2017-5-24 19:01:05
7#
那就换个思路,用Lines。
image.png752620849.png
image.png742983093.png
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-5-24 10:16:58
6#
gw0506 发表于 2017-5-24 09:50
没有看懂你的意思。
代码看起来没有问题,现在遇到的问题是什么呢?

内容是以 空行 然后 紧跟表格时,是去不掉空行的。
这个问题和之前你和我说过,Selection.Start = 0 定位到的是表格后面,而不是文档内容的开始。
所有,空行消不掉
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-5-24 10:16:56
5#
gw0506 发表于 2017-5-24 09:50
没有看懂你的意思。
代码看起来没有问题,现在遇到的问题是什么呢?

内容是以 空行 然后 紧跟表格时,是去不掉空行的。
这个问题和之前你和我说过,Selection.Start = 0 定位到的是表格后面,而不是文档内容的开始。
所有,空行消不掉
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-5-24 10:16:53
地板
gw0506 发表于 2017-5-24 09:50
没有看懂你的意思。
代码看起来没有问题,现在遇到的问题是什么呢?

内容是以 空行 然后 紧跟表格时,是去不掉空行的。
这个问题和之前你和我说过,Selection.Start = 0 定位到的是表格后面,而不是文档内容的开始。
所有,空行消不掉
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部