TXControl .NET 23 表格过大加载性能问题。
本帖最后由 KingMan 于 2017-6-8 20:37 编辑因为我的表格可能比较大,而且需要设置每个单元格的样式,如字体颜色,对齐,单元格宽度,线条宽度,线条颜色等。
经常会把界面卡在那里,出现假死状态,等2,3秒才显示出来。现在仅仅是 20 列 * 40行,就出现这样的情况,像医院的护理记录,时间长啦,数据越来越大,
20 列 * 200 行都有可能,这种情况那更玩不了啦。有没有什么方法性能比较高
如这个是加载后显示的
下面这个截图为加载时界面假死状态,或界面显示如下面图,在不停闪烁,不停刷新,界面卡顿严重
让我看看代码,如果不停闪烁说明在不停的刷新,这很可能是代码写的有问题导致不停刷新,这样还有办法调整。否则就没有办法优化了,只能对数据做处理了,比如每次只加载20行。 本帖最后由 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:29 编辑
代码有优化控件。
1. 创建Table后,先添加数据,后设置样式,最后在调Tables.Add,这样就只刷新一次。
2. 你在这些逻辑之外,加上
this.textControl1.SuspendLayout();
this.textControl1.ResumeLayout();
页:
[1]