Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / December 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tribbles - 14 Sep 2007 19:34 GMT
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();
       }
Bob Powell [MVP] - 15 Sep 2007 10:12 GMT
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.

Signature

--
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.

>I have a form which allows users to relaod data at runtime.
> Unfortunately, the operation of reloading and/or adding new criteria
[quoted text clipped - 64 lines]
>            this.PerformLayout();
>        }
tribbles - 17 Sep 2007 18:31 GMT
On Sep 15, 2:12 am, "Bob Powell [MVP]" <b...@spamkillerbobpowell.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).
Bob Powell [MVP] - 18 Sep 2007 10:21 GMT
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.

Signature

--
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.

> On Sep 15, 2:12 am, "Bob Powell [MVP]" <b...@spamkillerbobpowell.net>
> wrote:
[quoted text clipped - 15 lines]
> controls bundled into a user control that represents a row and I have
> 5 rows).
tribbles - 18 Sep 2007 22:09 GMT
On Sep 18, 2:21 am, "Bob Powell [MVP]" <b...@spamkillerbobpowell.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"
[quoted text clipped - 36 lines]
>
> - 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...
Bob Powell [MVP] - 09 Dec 2007 16:11 GMT
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.

Signature

--
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.

> On Sep 18, 2:21 am, "Bob Powell [MVP]" <b...@spamkillerbobpowell.net>
> wrote:
[quoted text clipped - 67 lines]
> infragestic controls to see what is going on, which is a bit
> frustrating...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.