Removing listbox flash in .NET

A

Andrus

I created form which uses double buffering for everything.
If form is resized, listbox content is flashing.
In MONO ListBox is resized smoothly.

How to fix code so that it does not flash in .NET also ?

Andrus.

using System.Windows.Forms;

public class Test
{
static void Main()
{
Application.Run(new ReportDialogForm());
}
}

class ReportDialogForm : Form
{
public ReportDialogForm()
{
DoubleBuffered = true;
tabControl1 = new BufferedTabControl();
tabPage1 = new BufferedTabPage();
reportListBox = new BufferedListBox();
tabControl1.Dock = DockStyle.Fill;
tabControl1.Controls.Add(tabPage1);
tabPage1.Controls.Add(reportListBox);
reportListBox.Dock = DockStyle.Fill;
Controls.Add(tabControl1);
for (int i = 0; i < 100; i++)
reportListBox.Items.Add("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
}

class BufferedListBox : ListBox
{
internal BufferedListBox()
{
DoubleBuffered = true;
}
}

class BufferedTabControl : TabControl
{
internal BufferedTabControl()
{
DoubleBuffered = true;
}
}

class BufferedTabPage : TabPage
{
internal BufferedTabPage()
{
DoubleBuffered = true;
}

}

BufferedTabControl tabControl1;
BufferedTabPage tabPage1;
BufferedListBox reportListBox;
}
 
J

Jeff Gaines

for (int i = 0; i < 100; i++)
reportListBox.Items.Add("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
}

I was able to speed up a ListView which took 38 seconds to add 1003 files
by adding them to an array of ListViewItems then using AddRange after the
loop, it now takes about 0.8 seconds.

May be worth a try with a ListBox, may be too quick for any flicker to be
noticed.
 
M

Mel Weaver

maybe using ListBox.SuspendUpdate() before your loop and the
ListBox.BeginUpdate() after your loop will help
 
A

Andrus

maybe using ListBox.SuspendUpdate() before your loop and the
ListBox.BeginUpdate() after your loop will help

Flashing occurs when listbox is resized.
Loop is running only in constructor.
So this does not have any effect.

Andrus.
 
A

Andrus

I was able to speed up a ListView which took 38 seconds to add 1003 files
by adding them to an array of ListViewItems then using AddRange after the
loop, it now takes about 0.8 seconds.

May be worth a try with a ListBox, may be too quick for any flicker to be
noticed.

Add code is running in constructor only.
The flashing occurs when form is resized.
Constructor speed does not have any affect for this.

Actual issues seems to be that .NET does not pass Doublebuffered setting to
underlying control.
See
https://bugzilla.novell.com/show_bug.cgi?id=417962

for related info.

Andrus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top