c#覆盖富文本框中的当前行(在写入之前将光标返回到行的左侧)

时间:2017-08-30 17:07:15

标签: c# wpf

我有一个Windows应用程序,我试图将当前下载的文件数量写入richtextbox。 我试图让它在同一条线上输出,覆盖过去的细节,但是,我只是设法附加以前的数据。

  

0.01 MB / 7.53 MB&m; 0.01 MB / 7.53 MB&m ... 0.08 MB / 7.53 MB&m ... 0.08 MB' s / 7.53 MB' s0.14 MB / 7.53 MB&#39.14 MB / 7.53 MB&#39.18 MB / 7.53 MB' s0 .24 MB / 7.53 MB&t; 2.24 MB / 7.53 MB&m; 2.27 MB / 7.53 MB&n.33 MB&#39 / s / 7.53 MB的0.33 MB / 7.53 MB的0.34 MB / 7.53 MB的0.39 MB / 7.53 MB&m.45 MB / 7.53 MB< 0.45 MB / 7.53 MB&#0. s2.5 MB / 7.53 MB&#0.52 MB / 7.53 MB& #39; s0.58 MB / 7.53 MB&s; 0.58 MB / 7.53 MB&m 3.65 MB / 7.53 MB&#0. s 0.65 MB&# 39; s / 7.53 MB< 0.71 MB / 7.53 MB< 0.71 MB&s; / 7.53 MB&#39.31 MB / 7.53 MB&#39 ; s0.79 MB / 7.53 MB&m; 0.85 MB / 7.53 MB&m; 0.90 MB / 7.53 MB&s.93.93 MB' s / 7.53 MB< 0.99 MB / 7.53 MB&s> 1.00 MB / 7.53 MB< 1.06 MB&/ s> 7.53 MB' s1 .06 MB / 7.53 MB< 12.12 MB / 7.53 MB&n.1.13 MB&#39 ; s / 7.53 MB&#39.1 s MB / 7.53 MB&s.1.19 MB / 7.53 MB< 1.25 MB / 7.53 MB' s1.26 MB&s; / 7.53 MB  1.32 MB / 7.53 MB&s.32 MB / 7.53 MB&s.38 MB' s / 7.53 MB< 1.39 MB / 7.53 MB> 1.44 MB / 7.53 MB< 1.50 MB / 7.53 MB' s1。 50 MB / 7.53 MB&s; 1.50 MB / 7.53 MB&s 1.57 MB / 7.53 MB&s 1.57 MB / 7.53 MB的1.63 MB / 7.53 MB的1.63 MB / 7.53 MB&s; 1.69 MB / 7.53 MB&s; 1.70 MB& #39; s / 7.53 MB&s; 17.75 MB / 7.53 MB&s1.81 MB / 7.53 MB&#391.81 MB / 7.53 MB&# 39; s1.81 MB&rs; 7.53 MB&s; 1.87 MB / 7.53 MB&s; 1.87 MB / 7.53 MB> 1.94 MB&#39 ; s / 7.53 MB> 1.94 MB / 7.53 MB&s 2.00 MB / 7.53 MB&s 2.00 MB / 7.53 MB' s2.06 MB&s; / 7.53 MB' 2.00 MB / 7.53 MB' s2.12 MB / 7.53 MB&s.42 MB' s / 7.53 MB' s2.18 MB / 7.53 MB&#29.1 MB / 7.53 MB&# 39; s2.25 MB / 7.53 MB&s; 2.25 MB / 7.53 MB' s2.31 MB / 7.53 MB&s.32 MB&#39 ; s / 7.53 MB&s 2.37 MB / 7.53 MB&s 2.34 MB / 7.53 MB&s 2.34 MB / 7.53 MB' s2.43 MB / 7.53 MB&s 2.50 MB / 7.53 MB&s 2.50 MB / 7.53 MB&s 2.56 MB' s / 7.53 MB< 2.56 MB / 7.53 MB&#2.s2.62 MB / 7.53 MB&#2.64 MB / 7.53 MB' s2。 70 MB / 7.53 MB&rs 2.71 MB / 7.53 MB&rs 2.77 MB / 7.53 MB&m 2.77 MB / 7.53 MB的2.84 MB / 7.53 MB的2.85 MB / 7.53 MB的2.91 MB / 7.53 MB&#2.92 MB& #39; s / 7.53 MB< 2.98 MB / 7.53 MB" 2.98 MB / 7.53 MB&#2.99 MB / 7.53 MB&# 39; s3.05 MB / 7.53 MB&m3.06 MB / 7.53 MB&s.32 MB&rbsp; 7.53 MB&n.32 MB&#39 ; s / 7.53 MB&n.3.12 MB / 7.53 MB&n.3.18 MB / 7.53 MB&n.3.19 MB / 7.53 MB' s3.19 MB / 7.53 MB&m.3.25 MB / 7.53 MB&n.35 MB&#3 9; s / 7.53 MB&s.33.30 MB / 7.53 MB&n.37 MB / 7.53 MB&n.37 MB / 7.53 MB&#39 ; s3.43 MB / 7.53 MB&n.33.3 MB / 7.53 MB&s.3.49 MB / 7.53 MB&n.3.50 MB' s / 7.53 MB&m.3.56 MB / 7.53 MB&m.3.56 MB / 7.53 MB&m 3.62 MB / 7.53 MB' s3 .62 MB / 7.53 MB&m 3.63 MB / 7.53 MB&n.3.69 MB / 7.53 MB&n.3.69 MB' s / 7.53 MB的3.69 MB / 7.53 MB的3.74 MB / 7.53 MB的3.80 MB / 7.53 MB' s 3.80 MB / 7.53 MB&m 3.87 MB / 7.53 MB&m 3.87 MB / 7.53 MB&n.3.93 MB / 7.53 MB& #39; s3.93 MB / 7.53 MB&s 39.99 MB / 7.53 MB&s.39.99 MB / 7.53 MB&m.45 MB&# 39; s / 7.53 MB< 4.11 MB / 7.53 MB< 4.11 MB / 7.53 MB> 4.48 MB / 7.53 MB&#39 ; s4.18 MB / 7.53 MB< 4.24 MB / 7.53 MB> 4.24 MB / 7.53 MB' s4.31 MB' s / 7.53 MB< 4.31 MB / 7.53 MB> 4.36 MB&/ 393 / MB& #39; s4.42 MB / 7.53 MB> 4.43 MB / 7.53 MB> 4.49 MB / 7.53 MB> 4.49 MB&# 39; s / 7.53 MB> 4.56 MB / 7.53 MB> 4.56 MB / 7.53 MB> 4.62 MB / 7.53 MB&#39 ; s4.62 MB / 7.53 MB> 4.67 MB / 7.53 MB> 4.74 MB / 7.53 MB> 4.74 MB' s / 7.53 MB&m4.80 MB / 7.53 MB&m4.80 MB / 7.53 MB&m 4.87 MB / 7.53 MB' s4 .87 MB / 7.53 MB< 4.93 MB / 7.53 MB> 4.93 MB / 7.53 MB&s.49.99 MB&#39 / s / 7.53 MB的5.05 MB / 7.53 MB的5.05 MB / 7.53 MB的5.18 MB / 7.53 MB的5.11 MB / 7.53 MB< 5.18 MB / 7.53 MB&#53.18 MB / 7.53 MB> 5.44 MB / 7.53 MB& #39; s5.24 MB / 7.53 MB&s; 3.30 MB / 7.53 MB&#39.31 MB / 7.53 MB&s.37 MB&# 39; s / 7.53 MB&s.37 MB / 7.53 MB> 5.42 MB / 7.53 MB> 5.48 MB / 7.53 MB&#39 ; s5.49 MB / 7.53 MB&s; 5.55 MB / 7.53 MB&s; 5.55 MB&# 39; s / 7.53 MB> 5.61 MB / 7.53 MB> 5.6-1 MB / 7.53 MB> 5.66 MB / 7.53 MB&#39 ; s5.68 MB / 7.53 MB&rs.3.74 MB / 7.53 MB&s; 5.8 MB / 7.53 MB&s 5.86 MB' s / 7.53 MB< 5.92 MB / 7.53 MB> 5.92 MB / 7.53 MB> 5.99 MB / 7.53 MB' s5 .99 MB / 7.53 MB&m.4.04 MB / 7.53 MB&#39.11 MB / 7.53 MB&#39.11 MB&#39 / s / MB / s 7.53 MB&#39.17 MB / 7.53 MB&r.47 MB​​ / 7.53 MB&s.63 MB / 7.53 MB' s6.24 MB / 7.53 MB&s.38 MB / 7.53 MB&s = 3.30 MB / 7.53 MB&s.36 MB / 7.53 MB& #39; s6.42 MB&rs; 7.53 MB&s.42 MB / 7.53 MB&s.48 MB / 7.53 MB&s.449 MB&# 39; s / 7.53 MB&#39.55 MB / 7.53 MB&#39.55 MB / 7.53 MB&#392 MB / 7.53 MB&#39 ; s6.62 MB / 7.53 MB&s 3.67 MB / 7.53 MB&s; 6.7 MB / 7.53 MB&#39.7 MB MB' s / 7.53 MB&s6.80 MB / 7.53 MB&s = 6.80 MB / 7.53 MB ' s6.86 MB / 7.53 MB&s = 6.86 MB / 7.53 MB&#39.92 MB / 7.53 MB&#39.93 MB& #39; s / 7.53 MB> 6.98 MB / 7.53 MB> 7.04 MB / 7.53 MB> 0.04 MB&/ s> 7.53 MB&# 39; s7.11 MB / 7.53 MB&s; 7.11 MB / 7.53 MB&#39.17 MB / 7.53 MB&#39.17 MB&#39 ; s / 7.53 MB&rs.3.23 MB / 7.53 MB&rs.3.24 MB / 7.53 MB&#39.29 MB / 7.53 MB' s7.29 MB / 7.53 MB&s.3.35 MB / 7.53 MB&s.36 MB / 7.53 MB&s.442 MB' / 7.53 MB' s7.42 MB / 7.53 MB' 7.49 MB / 7.53 MB&#39.49 MB / 7.53 MB' s7。 53 MB / 7.53 MB&rs.3.53 MB / 7.53 MB

     

下载完成!

我正在尝试(严重)做的是

  

7.53 MB / 7.53 MB

     

下载完成!

其中" 7.53 MB / 7.53 MB"换行,从" 0.01 MB / 7.53 MB""一开始一直到" 7.53 MB / 7.53 MB" (或者,文件有多大)。

我试过的代码是

            int firstCharIndex = richTextBox1.GetFirstCharIndexOfCurrentLine();


        // Calculate download speed and output it .
        if (richTextBox1.SelectionLength == 0)
        {
            int lineNumber = richTextBox1.GetLineFromCharIndex(firstCharIndex);
            richTextBox1.Focus();
            richTextBox1.AppendText(string.Format("{0} MB's / {1} MB's\n",
    (e.BytesReceived / 1024d / 1024d).ToString("0.00"),
    (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00")));
            firstCharIndex = richTextBox1.SelectionStart;
        }

我希望我已经说清楚了(基本上,我想用下载数据覆盖当前行,直到下载完成)。

有人能帮助我吗?

感谢

1 个答案:

答案 0 :(得分:0)

删除附加方法:

richTextBox1.Document.Blocks.Clear();
richTextBox1.Document.Blocks.Add(
                             new Paragraph(
                                 new Run(
                                     string.Format("{0} MB's / {1} MB's\n",(e.BytesReceived / 1024d / 1024d).ToString("0.00"),(e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00")
                                 )
                             );

更新:no erros