Solved

prevent screen-flickering? HOW?

Posted on 1997-08-18
10
1,422 Views
Last Modified: 2012-05-04
I would like to prevent the user from seeing the screen updating itself:

I have 1 mainform (Main) en let's say 2 'child'forms (it's not an MDI app).
The 2 'child'forms contain a lot of controls (24 editboxes, 30 labels, 1 listbox, 1 combobox, several buttons, 9 checkboxes, 9 spinedits, 3 groupboxes).
On my mainform there is are two buttons (one for each 'child'-form). When you press the button for 'child'form1 'child'form1 is created within the mainform.

PROBLEM:
~~~~~~~

When I switch between the two 'child' forms (via the buttons) you can see the controls being painted:
first the white boxes, then the lines and text.
How do I prevent this? I want the screen to popup at once when all the drawing is finished.

On the ATARI (years ago!) I let everything being painted on an offscreen bitmap. After all the painting was done I copied the bitmap to the screen...!

How do I do this in Delphi? How are the events working (onpaint, WMPAINT)?
createcompatibleBitmap/createCompatibleDC?

Thanx a million for your reaction!
0
Comment
Question by:ozeegers
  • 7
  • 3
10 Comments
 
LVL 2

Accepted Solution

by:
icampbe1 earned 200 total points
ID: 1341709
There is a first time rendering on the component's canvas that occurs for each control on the form.  This is what you are observing.  If you don't have to destroy and re-create the other two forms each time, that will work a lot better.  That is, you can use 'Form.Hide' and 'Form.Show' when you switch between them instead of completely destroying them and re-creating them.  Is it necessary to destroy them?

Painting can be controlled by overriding the controls 'paint' method.  This is called every time the control must repaint itself.  You might find this cleaner than grabbing the WM_PAINT message but it really doesn't matter which.

Some of the initial paint delay that you observe is the 'reading' of the control's published properties (like the text of an edit box or the caption of a label).  If you have a large and busy form like you do, the form will render more quickly with 'empty' controls.  If this is managable, you might try that and then fill them in as needed (or some combination of both).

I hope this helps,
Ian C.
0
 

Author Comment

by:ozeegers
ID: 1341710
Thank you for your quick answer.
I'm not so sure if it helps me any further. I'm not an expert in Delphi so..........
I am destroying my forms in order to keep resource consumption low (the user is able to choose between 30 forms to add to his list; the average user will add 10 forms to the list, so 10 forms with lots of control on is will consume very much resources?).
Could you please write a complete example on how I let windows draw the form on an offscreen bitmap (in memory) first and then copy the bitmap to the screen? I think that will solve the problem because it's not that slow but it's the building up of the control that one can see that is annoying....

Thank you very much in advance,

O.Zeegers
0
 

Author Comment

by:ozeegers
ID: 1341711
Thank you for your quick answer.
I'm not so sure if it helps me any further. I'm not an expert in Delphi so..........
I am destroying my forms in order to keep resource consumption low (the user is able to choose between 30 forms to add to his list; the average user will add 10 forms to the list, so 10 forms with lots of control on is will consume very much resources?).
Could you please write a complete example on how I let windows draw the form on an offscreen bitmap (in memory) first and then copy the bitmap to the screen? I think that will solve the problem because it's not that slow but it's the building up of the control that one can see that is annoying....

Thank you very much in advance,

O.Zeegers

BTW. What does the field 'incease point to' mean?
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1341712
The resources used by controls and forms is surprisingly low.  If you want to do a small test, just display the 'InstanceSize' of any object and I'm sure you'll be surprised.  I know when you look at something like a form, it seems big, but you have to remember that it is 'drawn', not a bitmap.

Try:   ShowMessage( IntToStr( Edit1.InstanceSize) );

Or any other object for that matter.  InstanceSize is declared in TObject, so you can use it on any object anywhere, as long as it has been instantiated (who makes up these words?).

With this in mind, you may re-think your ideas about keeping these forms created and ready to go.  It isn't the burden you might think.

Oh yeah, 'increase points to' is used to increase to points that you are offering for a solution in an effort to get someones attention.  Theoretically, the more you offer, the more likely you will have a question answered.  Not at all like the spirit of Christmas.

Cheers,
Ian C.

BTW.  Thanks for the points.
0
 

Author Comment

by:ozeegers
ID: 1341713
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:ozeegers
ID: 1341714
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341715
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341716
>Could you please write a complete example on how I let windows >draw the form on an offscreen bitmap (in memory) first and then >copy the bitmap to the screen?

please check the source on any errors!

Thanx!
0
 

Author Comment

by:ozeegers
ID: 1341717
>Could you please write a complete example on how I let
>windows draw the form on an offscreen bitmap (in memory)
>first and then copy the bitmap to the screen?


please check the source on any errors!
Thanx!
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1341718
Now I see, you stutter....

I know what you're asking for, but that's not how windows does it.  Windows sends a a WM_PAINT message to any control that must paint or draw itself because it must be rendered on the screen.  It isn't your choice per se.  You don't pre-draw, like on a bitmap, and then show it.  Every control on your form is responsible for painting itself as well, and Windows tells it when to do so.

A good portion of the delay you are seeing is the from the PROPERTIES like the lablel.caption and editbox.text being filled in after the constructor has run.   You'll notice that this delay is mostly the 'first time'.

If the main form is the one that's the most annoying, then you can try Application.ShowMainForm := FALSE;  until you are ready to show it, but at least it's ready to go.

I wasn't being evasive when I didn't give you an example of what we did in the old days.  It's just not the same.

Hope this helps a bit more,

Ian C.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now