Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DISPLAY INSTANTLY

Posted on 1999-07-20
29
Medium Priority
?
296 Views
Last Modified: 2010-08-05
I have two forms : Form1 , 800x600 , with a big jpeg image ( all client area ) and Form2 , 500x400 , with a jpeg image ( full Form2  ) .
When show or hide the Form2 over Form1, this flick . Ugly . But I fix that . I put in Form2 a panel and jpeg image in it . Now my Form1 is flicker free but I have a new problem : FOR 1-2 SEC I HAVE A 500X400 BLACK HOLE  ( I set panel to clBlack ) IN FORM1 UNTIL FORM2 IS DISPLAYED .

In conclusion : How can I display the Form2 instantly ? I can wait 1-2 sec to load FORM2 but I don't wish to see the black panel . Can I hide the loaded and to display only this is done ? Or else ?

Ginsonic

P.S. Please comment . If your comment help me I will notify you to put an answer .
0
Comment
Question by:ginsonic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
  • 4
  • +4
29 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1390072
beginupdate;
dostuff...
endupdate;

stops the canvas from redrawing until the dostuff is finished.
also could use application.processmessages
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390073
Ginsonic,

actually you still have the flicker, but with the panel you have it extended to a much larger degree (therefor you see the black background). Take the panel out and make sure the form doesn't paint its background. This is possible since the image covers all the client area. To avoid background clearing include the following code into the form:

type
  TMyForm = class(TForm)
  private
    procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;
  end;

  :

procedure TMyForm.WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;

begin
  Msg.Result := 1;
end;

The BeginUpdate/EndUpdate stuff inthe suggested is usually a good chice if you want to change many things before the screen should be updated. But it is definitly not a good choice to prevent flickering as in EndUpdate usually the entire window is invalidated, even if only small parts changed.

To make a window visible immediately after calling Show just call UpdateWindow(AForm.Handle). This call goes directly to the window procedure of the target window without using messages and returns when the window has finished its paintings.

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390074
hi ginsonic,

have you tried something like this?
(don't know if thsi helps, just not checked)

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Enabled := False;
  Form2 := TForm2.Create(Application);
  LockWindowUpDate(Form2.Handle);
  Form2.Show;
  LockWindowUpDate(0);
end;

meikl
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:GabeinOZ
ID: 1390075
A very easy way to fix this is to create your form2 and then release it with

form2:=tform2.create(application);
//make sure somewhere in here that your jpeg for this form is loaded and shown as well
form2.release;

in the oncreate of your main form and then just show it again....this will cache the form drawing and will eliminate your problem.

Gabe
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390076
Lischke,
I try your code but I receive the next error message :
"Unknown directive :'message' ".


To all ,
Today I will try the anothers comments .
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390077
Ooops, that's interesting. The message directive was there at least since Delphi 1 (don't know about BP for Windows). Would please post the code here so we can check what went wrong?

Ciao, Mike
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390078
I put exact your code :
type
 TForm = class(TForm)
 private
  procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;
end;

        :
 procedure TForm.WMEraseBkGnd(var Msg: TWMEraseBkGnd); ( this is the error ) message
      WM_ERASEBKGND;
 begin
    Msg.Result := 1;
 end;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390079
hi ginsonic,

remove message  WM_ERASEBKGND;
in the implementation-part

meikl
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390080
Again oops ;-) Meikl is right, my mistake...
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390081
Hi Lischke,
It work . But I have a little problem .
On Form1 I have over the big jpeg some panels with small jpeg . When I close Form2 I can see for 1 sec the panel and then the small images are repainted .
How can I eliminate that ?
If you help me to fix the problem I will add 50 points .

Nick aka ginsonic

P.S.I use the small images for buttons . When I press the mouse button the up image change with down image and create an animation effect ( I use a blending effect ) . If I delete the panel then the button will flick .

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1390082
ok, do this:

DON'T create/free the form each time it has to be displayed..
just CREATE it one in Project.dpr ..

to show it use Form2.Show
to close it use Form2.Hide or Form2.Close
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390083
I do that  bryan7 , but don't work .

Lischke,
I put a treeview in my Form2 and now , first is displayed the tree and then image .
But only for the first time . Then work perfect . How can I resolve the problem ?

Can I use UpdateWindow(AForm.Handle) for Form1 ? How ? Because I wish to show instantly , too .

Too many questions but hope to help me .
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390084
Hi Nick,

of course you can call UpdateWindow as often as you wish, nearly without time penalty. If there's a non-empty update area the the window will be updated immediatly else nothing happens. The good point here is that not only the window as such is updated but also all its child windows (in your case the tree).

There's another little trick which is good to know: As well as invalidating a window to tell what has changed you can also validate a window to avoid repaints. This in particular useful when you restore a window from a bitmap (as the result of an animation effect etc.) and you know there's nothing further to draw (function is ValidateRect).

For your additional-50-points-question: Try to hide the form just before you close it or use LockWindowUpdate. It seems that there comes from somewhere a refresh on close, which is very unusual, but the comfortability of the VCL has sometimes its price... Probably the ValidateRect with a nil rectangle parameter could do the job. Just try it and tell me your results.

Ciao, Mike
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390085
I found a better solution .
Before to close Form2 I show Form1 with
  Form1.Show;
  UpdateWindow(Form1.Handle);
and then CLOSE .

I have a last problem unfinished . I write up about this .
When I show for first time Form2 , only first time , I see for 1sec black background of Form2 . But only where I don't have in Form2 components : Tree and List . In areas where I have components all is OK ( transparent , I can see Form1 ) .
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390086
For your last problem the ValidateRect would be ideal I think. The background of Form2 is not painted where the child windows are placed because these areas are taken out of the validation region. Just try to validate the entire form directly after you called Show. It might be necessary to invalidate it later again but try it first with validation. I assume you don't want to keep Form2 from erasing its background?

Ciao, Mike
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390087
Can you type some codes ?
It's new for me .

0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390088
Oh, this is easy. Just use:

  :
  Form2.Show;
  // this will avoid the initial painting I hope
  ValidateRect(Form2.Handle, nil);
  :
  // if the other stuff on the form don't initiate a
  // repaint of the form on their loading then
  // you might need to do Form2.Refresh later

Ciao, Mike
0
 
LVL 2

Expert Comment

by:mahara
ID: 1390089
well, this is nothing about the rest of the comments to your question, so only about your flick problem...

hide the window to an unseen coordinate until it loads.
like .left:=-3000

this always works.

i'm sure it may not make sense after all that low-level things talked about here but.. simply the one you need is this ?
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390090
Hi mahara,

great to have a new face here at E-E :-) You should, though, be so polite to respect the requests of others (in particular Ginsonic has explicitly written to post comments not answers). The second point is, your solution will not work as the form still has to be displayed later (when it is positioned onto its final place) and must still do the same paintings. The windows aren't updated when the form isn't at least partially visible (window handles will be created when the control is shown the first time).

Ciao, Mike
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390091
Be cool Lischke !

Sorry mahara ,
I don't test your answer yet but please let me oportunity to choice the answer .
If your's is good I will notify you to put an answer .

0
 
LVL 2

Expert Comment

by:mahara
ID: 1390092
sorry i'm really new to the system and this is how i differentiate between a comment and an answer..
anyway, i meant: sometimes solutions maybe simpler. I believe that the correct implementation of what i've told can prevent the problem. (Sometimes a practical solution is better than a stronger but harder one)
again sorry if anything is misunderstood
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390093
mahara ,
I test your propose . Lischke have right . Don't work . Sorry and thanks for help . Hope to help me in future .Maybe you try for last 50 points .

Lischke , sorry to . Your last propose don't work . At the first displayt I have same bug and to next shows I lost the jpeg image . Only black color and components .

BUT NOW THE POINTS .

Lischke you tack my 100 points for help . Thanks .

And the promised 50 points are stil available . Anyone can send propose here ( I don't know if is posible after what I accept an answer ) or to my mail address nick@decebal.ro and I will post a new answer with title "50 points for .....your name" .

I really need help to fix my last problem with display .
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390094
mahara ,
I test your propose . Lischke have right . Don't work . Sorry and thanks for help . Hope to help me in future .Maybe you try for last 50 points .

Lischke , sorry too . Your last propose don't work . At the first displayt I have same bug and to next shows I lost the jpeg image . Only black color and components .

BUT NOW THE POINTS .

Lischke you tack my 100 points for help . Thanks .

And the promised 50 points are stil available . Anyone can send propose here ( I don't know if is posible after what I accept an answer ) or to my mail address nick@decebal.ro and I will post a new answer with title "50 points for .....your name" .

I really need help to fix my last problem with display .
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390095
Hey ,
Sorry for duplicate the message .
Lischke send an answer .

Nick aka ginsonic
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1390096
hey hey hey ..... wait..

I want 200 points for my comment   !!!


;) ( only joing.. )
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1390097
hey hey hey ..... wait..

I want 200 points for my comment   !!!


;) ( only joking.. )
0
 
LVL 10

Accepted Solution

by:
Lischke earned 400 total points
ID: 1390098
Sad that I could not help with all your questions, but glad to help you anway.

Ciao, Mike
0
 
LVL 9

Author Comment

by:ginsonic
ID: 1390099
Hey Bryan7 ,
Help you my sample code for change the resolution ? I have more tips about .
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1390100
Hi.. I didn't forget about it.. sorry for the delay.. it's just that I have many things to do and test lately..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

688 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