找回密码
 立即注册

QQ登录

只需一步,快速开始

KingMan

中级会员

68

主题

148

帖子

554

积分

中级会员

积分
554
KingMan
中级会员   /  发表于:2017-6-8 20:35  /   查看:3095  /  回复:3
本帖最后由 KingMan 于 2017-6-8 20:37 编辑

因为我的表格可能比较大,而且需要设置每个单元格的样式,如字体颜色,对齐,单元格宽度,线条宽度,线条颜色等。
经常会把界面卡在那里,出现假死状态,等2,3秒才显示出来。现在仅仅是 20 列 * 40行,就出现这样的情况,像医院的护理记录,时间长啦,数据越来越大,
20 列 * 200 行都有可能,这种情况那更玩不了啦。有没有什么方法性能比较高

如这个是加载后显示的
202855e3seaemw0s0qaz3w.png608447265.png

下面这个截图为加载时界面假死状态,或界面显示如下面图,在不停闪烁,不停刷新,界面卡顿严重

图片.png310704039.png

3 个回复

倒序浏览
gw0506
超级版主   /  发表于:2017-6-9 10:38:18
沙发
让我看看代码,如果不停闪烁说明在不停的刷新,这很可能是代码写的有问题导致不停刷新,这样还有办法调整。否则就没有办法优化了,只能对数据做处理了,比如每次只加载20行。
回复 使用道具 举报
KingMan
中级会员   /  发表于:2017-6-9 12:00:54
板凳
本帖最后由 KingMan 于 2017-6-9 14:01 编辑
gw0506 发表于 2017-6-9 10:38
让我看看代码,如果不停闪烁说明在不停的刷新,这很可能是代码写的有问题导致不停刷新,这样还有办法调整。 ...


        private void button13_Click(object sender, EventArgs e)
        {
            m_iTableId += 1;
            if (textControl1.Tables.Add(200, 20, m_iTableId) == false)
            {
                MessageBox.Show("添加表格失败");
                return;
            };
        }


        private void button17_Click(object sender, EventArgs e)
        {
            TXTextControl.Table pCurrentTable = this.textControl1.Tables.GetItem();
            if (pCurrentTable == null)
                return;
            int i = 1;
            TableCellFormat pCellFormat = new TableCellFormat();
            pCellFormat.VerticalAlignment = VerticalAlignment.Center;
            pCellFormat.LeftBorderColor = Color.Black;
            pCellFormat.TopBorderColor = Color.Black;
            pCellFormat.RightBorderColor = Color.Black;
            pCellFormat.BottomBorderColor = Color.Black;
            pCellFormat.LeftBorderWidth = 1;
            pCellFormat.TopBorderWidth = 1;
            pCellFormat.RightBorderWidth = 1;
            pCellFormat.BottomBorderWidth = 1;


            foreach (TableCell pNext in pCurrentTable.Cells)
            {
                pNext.Text = i.ToString();
                pNext.CellFormat = pCellFormat;
                i += 1;
            }
            
        }

就整么一个简单的例子,耗时20 * 200 = 4000 单元格,耗时3分钟还没有搞完,这性能有点问题。。。

下面这个例子,就消耗 2017-06-09 13:52:07 2017-06-09 13:52:46  差不多40s,而且没有什么业务逻辑,如果
加上相关行业业务逻辑,那可用性更加不用说啦,客户完全接受不了这样的用户体验。 40 * (5 * 20) = 4000 单元格
        private void button18_Click(object sender, EventArgs e)
        {
            String sTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            for (int k = 1; k <= 40; k++)
            {
                m_iTableId += 1;
                textControl1.Selection.Text = "\n";
                if (textControl1.Tables.Add(5, 20, m_iTableId) == false)
                {
                    MessageBox.Show("添加表格失败");
                    return;
                };

                TXTextControl.Table pCurrentTable = this.textControl1.Tables.GetItem(m_iTableId);
                if (pCurrentTable == null)
                    return;
                int i = 1;
                TableCellFormat pCellFormat = new TableCellFormat();
                pCellFormat.VerticalAlignment = VerticalAlignment.Center;
                pCellFormat.LeftBorderColor = Color.Black;
                pCellFormat.TopBorderColor = Color.Black;
                pCellFormat.RightBorderColor = Color.Black;
                pCellFormat.BottomBorderColor = Color.Black;
                pCellFormat.LeftBorderWidth = 1;
                pCellFormat.TopBorderWidth = 1;
                pCellFormat.RightBorderWidth = 1;
                pCellFormat.BottomBorderWidth = 1;


                foreach (TableCell pNext in pCurrentTable.Cells)
                {
                    pNext.Text = i.ToString();
                    //pNext.CellFormat = pCellFormat;
                    i += 1;
                }

            }
            sTime += (" " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            textBox3.Text = sTime;
        }



回复 使用道具 举报
gw0506
超级版主   /  发表于:2017-6-9 14:23:41
地板
本帖最后由 gw0506 于 2017-6-9 14:29 编辑

代码有优化控件。
1. 创建Table后,先添加数据,后设置样式,最后在调Tables.Add,这样就只刷新一次。
2. 你在这些逻辑之外,加上
  1. this.textControl1.SuspendLayout();
  2. this.textControl1.ResumeLayout();
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部