View previous topic :: View next topic |
Author |
Message |
ychung
Joined: 25 Jan 2007 Posts: 16
|
Posted: Thu Jan 25, 2007 1:59 pm Post subject: Getting slower after selected row changed repeatedly |
|
|
Hi there,
I've encountered an issue that the speed is getting slower and CPU loading is reaching higer when selected row changed repeatedly by up/down keys. In my application, I use custom CellWidget to draw the content. In each cell, I draw an icon and a string. There are total 4 of these columns and 9 normal pure text columns.
When my application just started, everything is fine and the selection changing(scroll up/down by keys) is fast. After couple times of up/down scrolls, the speed just getting slower and slower.
Please help me identify the problem.
VirtualTree version: 3.2.1.0
.Net Framework: 2.0.50727
PS:
I've disabled all the event handlers attached to VirtualTree and the behavior is still the same.
Here is what I do in the CellWidget to do the drawing. The icon is a static member of data object.
public abstract class JobCellWidgetIconTextColumn: CellWidget
{
public JobCellWidgetIconTextColumn(RowWidget rowWidget, Column column)
: base(rowWidget, column)
{
}
protected abstract Icon GetIcon();
protected abstract String GetText();
protected abstract bool DoCustomizeDrawing();
protected override void PaintForeground(System.Drawing.Graphics graphics, Infralution.Controls.Style style, bool printing)
{
Rectangle bounds = Bounds;
if (DoCustomizeDrawing())
{
Icon icon = GetIcon();
String text = GetText();
bool bDrawIcon = (icon != null);
Rectangle iconBounds = bounds;
if (bDrawIcon)
{
iconBounds.Width = icon.Width;
iconBounds.Height = icon.Height;
iconBounds.Y += ((bounds.Height-icon.Height)/2);
graphics.DrawIcon(icon, iconBounds);
}
Rectangle textBounds = bounds;
if (bDrawIcon)
{
textBounds.X = iconBounds.Right + 2;
textBounds.Width -= (iconBounds.Width + 2);
}
PaintText(graphics, textBounds, style, text);
}
else
{
base.PaintForeground(graphics, style, printing);
}
} |
|
Back to top |
|
|
ychung
Joined: 25 Jan 2007 Posts: 16
|
Posted: Thu Jan 25, 2007 2:36 pm Post subject: |
|
|
I think I've found the cause. if I comment out the following code:
// graphics.DrawIcon(icon, iconBounds);
The problem disappeared. So, it's not a VirtualTree issue.
I took a further study by searching Graphics.DrawIcon. Someone stats that DrawIcon is extremely slow comparing to DrawImage.
I will try to use bitmap images instead of icons to do the drawing.
Thanks! |
|
Back to top |
|
|
ychung
Joined: 25 Jan 2007 Posts: 16
|
Posted: Thu Jan 25, 2007 3:37 pm Post subject: |
|
|
After switching to PNG format and use DrawImage instead, the getting slower issue is gone! Nice!
However there a small problem here.. Please look the code below.
RowData.Icon seems still causing some performance issuse as above post mentioned, not very serious but still noticeable after some up/downs.
protected override void OnGetRowData(Row row, RowData rowData)
{
if (row.Item is Job)
{
Job job = (Job)row.Item;
rowData.Icon = job.JobIcon;
rowData.IconSize = 16;
}
} |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jan 25, 2007 10:39 pm Post subject: |
|
|
The DrawIcon problem is due to changes made between .NET 1.1 and 2.0. The .NET 2.0 version is at least 100 times slower. We don't use the Graphics.DrawIcon method for this reason (it also does not support drawing to printer contexts).
The Infralution.Controls.DrawingUtilities class provides DrawIcon methods that we use and you can also call from your code.
Quote: | However there a small problem here.. Please look the code below.
RowData.Icon seems still causing some performance issuse as above post mentioned, not very serious but still noticeable after some up/downs.
protected override void OnGetRowData(Row row, RowData rowData)
{
if (row.Item is Job)
{
Job job = (Job)row.Item;
rowData.Icon = job.JobIcon;
rowData.IconSize = 16;
}
} |
I don't think this code should be causing a performance problem - unless it is in the way you have implemented the job.JobIcon method. You should ensure that this is not loading a new icon each time. _________________ Infralution Support |
|
Back to top |
|
|
ychung
Joined: 25 Jan 2007 Posts: 16
|
Posted: Fri Jan 26, 2007 1:59 am Post subject: |
|
|
I will check my code and thanks for help! |
|
Back to top |
|
|
|