WinForms is rendering extremely slow

S

schoenfeld1

My .NET 2 winforms application is extremely slow at rendering itself.

I loaded my application and then got a small notepad window and dragged
it infront of my main application window for a while - making circles.
I could get a 'drag effect' over the entire application window because
my app did not even paint itself in all that time.

It never used to be this slow on .net 1.1. Any ideas what could be
causing this?
 
S

schoenfeld1

My .NET 2 winforms application is extremely slow at rendering itself.

I loaded my application and then got a small notepad window and dragged
it infront of my main application window for a while - making circles.
I could get a 'drag effect' over the entire application window because
my app did not even paint itself in all that time.

It never used to be this slow on .net 1.1. Any ideas what could be
causing this?

For anyone having the same problem, please note the following:

#1: Executing the application under VS.NET 2005 IDE is horrendously
slow. It looks like the IDE affects the internal rendering somewhat.
Running standalone improves the problem a lot.

#2: If you are dynamically adding controls to some panel, and those
controls have layout managers or AutoScroll set to true, then you may
want to set
- set the size of the control to it's correct size; AND
- perform layout on that control
BEFORE adding it to the container panel.

CODE SNIPPET:
view.Dock = DockStyle.Fill;
view.Name = "VIEW";
view.TabIndex = 0;
view.Location = new Point(
splitContainer.Panel2.Padding.Left,
splitContainer.Panel2.Padding.Top
);
view.Size = new Size(
splitContainer.Width -
(splitContainer.SplitterDistance +
splitContainer.SplitterWidth) -
(splitContainer.Panel2.Padding.Left +
splitContainer.Panel2.Padding.Right),
splitContainer.Height -
(splitContainer.Panel2.Padding.Top +
splitContainer.Panel2.Padding.Bottom)
);
view.PerformLayout(); <--- (1)
splitContainer.Panel2.Controls.Add(view);
splitContainer.Panel2.ResumeLayout(false); <--- (2)

(1) = perform layout on the control before it's added to parent
(2) = after added to parent, do not do any layout processing and the
redundant re-paints dont get invoked (hopefully).

This improved the performance, and usability, quite a bit!
 
A

AnsweringMachine

Nice tip.

Op might also need to set the DoubleBuffered property of the form to
True.
 

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