HighTechTalks DotNet Forums  

How do you turn off painting/redraw for a user control?

Dotnet Framework (WinForms Controls) microsoft.public.dotnet.framework.windowsforms.controls


Discuss How do you turn off painting/redraw for a user control? in the Dotnet Framework (WinForms Controls) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
tribbles
 
Posts: n/a

Default How do you turn off painting/redraw for a user control? - 09-14-2007 , 02:34 PM






I have a form which allows users to relaod data at runtime.
Unfortunately, the operation of reloading and/or adding new criteria
records is very slow and you can see all of the control being painted
slowly over the 3 second transacation. I would like to suspend all
painting, redrawing and refreshing of the panel that contains all of
these user controls (test case as over 4 user controls that are made
up of 10-20 elements each (controls and other user controls)) until
after everything has been added. I tried a varierty of things,
include SuspendLayout, override OnPaint and only calling
base.OnPaint() when I set a special flag, etc... It is not working,
when each control is added to another, painting occurs. I have even
tried dubble buffering sets... I thought I knew how onPaint worked
before I tackle this problem, but now I'm pretty confused as it seems
drawing is occurring outside of the onPaint events. Before I started
playign with code I set some counters to see how often onPaint was
called for the most nested userControl I had in the form when I was
creating a new series of criteria record. I was getting counts of
40-50 onPaint calls during the creation process.

Below is a test refresh function in which I clear the panel and re-
create everything... I'm using this to try and find a solution for
the painting problems. The idea if to have a blank screen until
everything is created and then paint the screen, rather than seeing
all sorts of graphic artifacts for a couple of seconds...

private void RefeshCriteria(SortedList<int, CriteriaBase>
sortedCriteria) {
Refreshing = true;
//
// Clear out the old controls.
//
panelCriteria.Controls.Clear();
this.SuspendLayout();

if (sortedCriteria == null) return;
//
// Add each of our criteria controls. We have to add the
control in reverse list
// order since the MS docking puts the last control added
on the top of the list
// when using Top dock style.
//
for (int sequence = sortedCriteria.Count; sequence > 0;
sequence--) {
CriteriaBase criteria = sortedCriteria[sequence];

CriteriaListComponentControl criteriaControl = new
CriteriaListComponentControl(
criteria, filterControls, valueControls,
showMessages);

criteriaControl.Changed += new
ChangedDelegate(OnChanged);
criteriaControl.OnSelect += new
SelectedDelegate(CriteriaSelected);
criteriaControl.Dock = DockStyle.Top;

criteriaControl.SuspendLayout();

panelCriteria.Controls.Add(criteriaControl);

criteriaControl.ResumeLayout();
}

Refreshing = false;
this.ResumeLayout();
this.PerformLayout();
}


Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: How do you turn off painting/redraw for a user control? - 09-15-2007 , 05:12 AM






I don't think this is possible in any sensible way. The wrappers that .NET
uses are effectively a parallel system to the Win32 system underneath and
the OnPaint methods and Paint handlers are courteous reporting of what has
already happened in the Win32 control so by the time you see it the painting
of child controls has already been initiated.

Your best bet is to revisit the user controls themselves to see if you have
inefficiencies in the children that are holding things up.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"tribbles" <shiretrib (AT) yahoo (DOT) com> wrote

Quote:
I have a form which allows users to relaod data at runtime.
Unfortunately, the operation of reloading and/or adding new criteria
records is very slow and you can see all of the control being painted
slowly over the 3 second transacation. I would like to suspend all
painting, redrawing and refreshing of the panel that contains all of
these user controls (test case as over 4 user controls that are made
up of 10-20 elements each (controls and other user controls)) until
after everything has been added. I tried a varierty of things,
include SuspendLayout, override OnPaint and only calling
base.OnPaint() when I set a special flag, etc... It is not working,
when each control is added to another, painting occurs. I have even
tried dubble buffering sets... I thought I knew how onPaint worked
before I tackle this problem, but now I'm pretty confused as it seems
drawing is occurring outside of the onPaint events. Before I started
playign with code I set some counters to see how often onPaint was
called for the most nested userControl I had in the form when I was
creating a new series of criteria record. I was getting counts of
40-50 onPaint calls during the creation process.

Below is a test refresh function in which I clear the panel and re-
create everything... I'm using this to try and find a solution for
the painting problems. The idea if to have a blank screen until
everything is created and then paint the screen, rather than seeing
all sorts of graphic artifacts for a couple of seconds...

private void RefeshCriteria(SortedList<int, CriteriaBase
sortedCriteria) {
Refreshing = true;
//
// Clear out the old controls.
//
panelCriteria.Controls.Clear();
this.SuspendLayout();

if (sortedCriteria == null) return;
//
// Add each of our criteria controls. We have to add the
control in reverse list
// order since the MS docking puts the last control added
on the top of the list
// when using Top dock style.
//
for (int sequence = sortedCriteria.Count; sequence > 0;
sequence--) {
CriteriaBase criteria = sortedCriteria[sequence];

CriteriaListComponentControl criteriaControl = new
CriteriaListComponentControl(
criteria, filterControls, valueControls,
showMessages);

criteriaControl.Changed += new
ChangedDelegate(OnChanged);
criteriaControl.OnSelect += new
SelectedDelegate(CriteriaSelected);
criteriaControl.Dock = DockStyle.Top;

criteriaControl.SuspendLayout();

panelCriteria.Controls.Add(criteriaControl);

criteriaControl.ResumeLayout();
}

Refreshing = false;
this.ResumeLayout();
this.PerformLayout();
}



Reply With Quote
  #3  
Old   
tribbles
 
Posts: n/a

Default Re: How do you turn off painting/redraw for a user control? - 09-17-2007 , 01:31 PM



On Sep 15, 2:12 am, "Bob Powell [MVP]" <b... (AT) spamkillerbobpowell (DOT) net>
wrote:
Quote:
Your best bet is to revisit the user controls themselves to see if you have
inefficiencies in the children that are holding things up.

I've come across something that is working ok, but is much slower than
expected.. I create everything in a panel is not linked to anything
and then once all the children are created, I add the panel to the
screen. For my test case is takes about 3 seconds to create
everything on the panel. The suprising part is that it takes 1.5
seconds for the program to add the panel to the screen. It looks
quite a bit better than adding all the controls directly to the screen
of course, but I assumed it would take a fraction of a secont to
render and I'm confused as to why it would take so long to render a
bunch of textboxes, checkboxes and dropdowns (I have roughly 10
controls bundled into a user control that represents a row and I have
5 rows).



Reply With Quote
  #4  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: How do you turn off painting/redraw for a user control? - 09-18-2007 , 05:21 AM



Do you have other code in these controls such as changed event handlers that
in-turn fire off an Invalidate or something. These can cause "ringing"
poblems where the whole system goes mad sending updates for a while and then
takes a while to setle down.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"tribbles" <shiretrib (AT) yahoo (DOT) com> wrote

Quote:
On Sep 15, 2:12 am, "Bob Powell [MVP]" <b... (AT) spamkillerbobpowell (DOT) net
wrote:

Your best bet is to revisit the user controls themselves to see if you
have
inefficiencies in the children that are holding things up.


I've come across something that is working ok, but is much slower than
expected.. I create everything in a panel is not linked to anything
and then once all the children are created, I add the panel to the
screen. For my test case is takes about 3 seconds to create
everything on the panel. The suprising part is that it takes 1.5
seconds for the program to add the panel to the screen. It looks
quite a bit better than adding all the controls directly to the screen
of course, but I assumed it would take a fraction of a secont to
render and I'm confused as to why it would take so long to render a
bunch of textboxes, checkboxes and dropdowns (I have roughly 10
controls bundled into a user control that represents a row and I have
5 rows).



Reply With Quote
  #5  
Old   
tribbles
 
Posts: n/a

Default Re: How do you turn off painting/redraw for a user control? - 09-18-2007 , 05:09 PM



On Sep 18, 2:21 am, "Bob Powell [MVP]" <b... (AT) spamkillerbobpowell (DOT) net>
wrote:
Quote:
Do you have other code in these controls such as changed event handlers that
in-turn fire off an Invalidate or something. These can cause "ringing"
poblems where the whole system goes mad sending updates for a while and then
takes a while to setle down.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consultinghttp://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Trickshttp://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQhttp://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"tribbles" <shiret... (AT) yahoo (DOT) com> wrote in message

news:1190050310.148258.239290 (AT) 22g2000hsm (DOT) googlegroups.com...



On Sep 15, 2:12 am, "Bob Powell [MVP]" <b... (AT) spamkillerbobpowell (DOT) net
wrote:

Your best bet is to revisit the user controls themselves to see if you
have
inefficiencies in the children that are holding things up.

I've come across something that is working ok, but is much slower than
expected.. I create everything in a panel is not linked to anything
and then once all the children are created, I add the panel to the
screen. For my test case is takes about 3 seconds to create
everything on the panel. The suprising part is that it takes 1.5
seconds for the program to add the panel to the screen. It looks
quite a bit better than adding all the controls directly to the screen
of course, but I assumed it would take a fraction of a secont to
render and I'm confused as to why it would take so long to render a
bunch of textboxes, checkboxes and dropdowns (I have roughly 10
controls bundled into a user control that represents a row and I have
5 rows).- Hide quoted text -

- Show quoted text -
I am seeing the 'event storm' occur with some debugging and profilign
tools I have. My user controls directly have very few triggering
events. However, I use a tab control from Infragestics to host my
user control on one of its tabs and it has a couple of events being
triggered hundreds of times during all of this. My current plans is
to switch to the MS tab control to see if this problem goes away, as I
can not descern any reasonable reason for the event storm, nor can I
track exactly what is triggering it. Near as I can tell, the event
storm starts when I add the panel with my user controls to the tab
page.

As for the creation of my user controls, they do have their own event
storms going on (thus the 3 seconds) but I understand those and I'm
slowly working thru them. By the time I added the user panel with my
custom controls on it to the tab page, my event storm from the items
changes is finished. When I add the panel, my user controls are
getting 40+ refresh calls before being fully rendered. Yet none of my
Changed events are firing... Also the background paint event seems to
be called most often...

While I am havign good success tracing what happens when I place my
controls in the MS panel... I've been unable to trace through the
infragestic controls to see what is going on, which is a bit
frustrating...



Reply With Quote
  #6  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: How do you turn off painting/redraw for a user control? - 12-09-2007 , 11:11 AM



Are you using combo-boxes? One of the classic problems with data bound combo
boxes is that they fire their SelectedItemChanged event as each item is
bound.

As to your use of Infragistics tools, be aware that Infragistics uses
different principles to those of Windows Forms and tuning these controls can
present a problem. As this is an essentially Microsoft forum I suggest you
hit the Ifragistics dedicated newsgroups.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"tribbles" <shiretrib (AT) yahoo (DOT) com> wrote

Quote:
On Sep 18, 2:21 am, "Bob Powell [MVP]" <b... (AT) spamkillerbobpowell (DOT) net
wrote:
Do you have other code in these controls such as changed event handlers
that
in-turn fire off an Invalidate or something. These can cause "ringing"
poblems where the whole system goes mad sending updates for a while and
then
takes a while to setle down.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consultinghttp://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and
Trickshttp://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+
FAQhttp://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"tribbles" <shiret... (AT) yahoo (DOT) com> wrote in message

news:1190050310.148258.239290 (AT) 22g2000hsm (DOT) googlegroups.com...



On Sep 15, 2:12 am, "Bob Powell [MVP]" <b... (AT) spamkillerbobpowell (DOT) net
wrote:

Your best bet is to revisit the user controls themselves to see if you
have
inefficiencies in the children that are holding things up.

I've come across something that is working ok, but is much slower than
expected.. I create everything in a panel is not linked to anything
and then once all the children are created, I add the panel to the
screen. For my test case is takes about 3 seconds to create
everything on the panel. The suprising part is that it takes 1.5
seconds for the program to add the panel to the screen. It looks
quite a bit better than adding all the controls directly to the screen
of course, but I assumed it would take a fraction of a secont to
render and I'm confused as to why it would take so long to render a
bunch of textboxes, checkboxes and dropdowns (I have roughly 10
controls bundled into a user control that represents a row and I have
5 rows).- Hide quoted text -

- Show quoted text -

I am seeing the 'event storm' occur with some debugging and profilign
tools I have. My user controls directly have very few triggering
events. However, I use a tab control from Infragestics to host my
user control on one of its tabs and it has a couple of events being
triggered hundreds of times during all of this. My current plans is
to switch to the MS tab control to see if this problem goes away, as I
can not descern any reasonable reason for the event storm, nor can I
track exactly what is triggering it. Near as I can tell, the event
storm starts when I add the panel with my user controls to the tab
page.

As for the creation of my user controls, they do have their own event
storms going on (thus the 3 seconds) but I understand those and I'm
slowly working thru them. By the time I added the user panel with my
custom controls on it to the tab page, my event storm from the items
changes is finished. When I add the panel, my user controls are
getting 40+ refresh calls before being fully rendered. Yet none of my
Changed events are firing... Also the background paint event seems to
be called most often...

While I am havign good success tracing what happens when I place my
controls in the MS panel... I've been unable to trace through the
infragestic controls to see what is going on, which is a bit
frustrating...



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.