Link to home
Start Free TrialLog in
Avatar of AnswerTheMan
AnswerTheMan

asked on

something about VB simple FORMS

i have a form which is heavy loaded with a lot of controls, some of them are graphics.
now, even when loading all in the back, before the form is displayed - only the SHOW or Visible=true - takes quite a lot of time to make the form displayed in its stable-final look (on my 366MHZ,128MB it takes about 1-2 seconds). as i said - it's a heavy one.
but that's not the problem....

the problem is that in a certain situation - i have to run a function just in the moment the form becomes stable and fully displayed. NOT BEFORE. NOT AFTER. then - hide the form.
as far as i know - there is no EVENT that fired on the moment the form becomes stable.
i've tried all traditional events (Activate, GotFocus, Resize, Paint) but all fired before all the form's controls are fully displayed.
MSDN does not mention that issue when dealing in "Life Cycle of Forms".

well ?
Avatar of vbmitch
vbmitch

Try putting a timer in with a very small interval, 1 works well, make it something like this:

Sub Timer1_Timer ()
'Put functions here
Timer1.enabled = false 'So it only calls once
End Sub

Set the timer to enabled, and run the project. It should activate when you want it to.
how bout initialize event?
use Activate event:

Option Explicit
Private initDone As Boolean

Private Sub Form_Activate()
    If Not initDone Then
        ' do something
        initDone = True
    End If
End Sub

If all the form's controls are not fully displayed, this means:
- you are using async operation (e.g. DataGrid, the solution is to use AsyncReadComplete event), or
- you have DoEvents statement in your code (remove it)
Use a module to perform your form load. Place a Sub Main procedure in it.. and change the Project properties to start the project there. In your sub main.. put the following:

Private Sub Main ()

   frmSplashScreen.Show ' eye candy

   Load frmLoadedWithControls
   Laod frmBeginningScreen

   frmSplashScreen.Hide ' All forms loaded.. no more eye candy

   frmLoadedWithControls.Show
   
   ' Once and done processing

   frmLoadedWithControls.Hide

   frmBeginningScreen.Show

End Sub
Ameba:
I don't necessarily agree with using the Form Activate event.. but you are absolutley right on the mark with the (Ameba writes):

If all the form's controls are not fully displayed, this means:
- you are using async operation (e.g. DataGrid, the solution is to use AsyncReadComplete event), or
- you have DoEvents statement in your code (remove it)

Well keyed.. <smile>.

Avatar of AnswerTheMan

ASKER

BHHH.... a timer.... thanks but NO.
this app should do the job the moment the form is fully displaye on both 486 machine with 16 MB ram andd on P-3 600 machine with 256 mb ram.
would the suggested timer will provide what i'm after on both machins ? you know the answer.
ameba :
there is no async operation whatsoever involved in loading the form's controls - nor DoEvents statement.

i've checked the Activate event in many ways, an i know FOR SURE that it is
fired BEFORE all controls are set and stable.




wsh2 :
since i wrote that all i need is to capture the moment everything is stable -
splash screen is not relevant to the question. it won't give me any indication for what i'm after.

Just put the splash screen there for eye candy.. (by the sounds of all that you are loading.. you need a bit if time). The Load statements should perform synchroniously (ie no disply).. as such.. the form should not show until the load is done. Give it a try.. <smile>.
just a thought but i have no idea of its validity; the controls collection from what I understand enumerates all the LOADED controls of the form.  therefore since you are the designer you are aware of the number of controls before the program is executed.  if what i believe about the collections is true can you just perform a check to see if the controls.count property matches the total number of controls that are on the form.  if i'm way off base here someone enlighten me as to the life cycle of the controls collections of a form.  or do i need to post my own question for that? =)
If there was some reason given as to why this form only has to be displayed long enough for one function to run, we might be able to come up with a solution that didn't even require it to be displayed at all.
Foyal:
I am in complete agreement with you.. a form LOAD (without any display) should suffice to get everything properly  initialized and created. The questioner's need to display the form briefly and then immediately hide it.. is certainly a mystery to me as well.. <smile>.

Azra:
Forms and the Controls on them exist until the form is completely dereferenced AND unloaded.. <smile>.
<sheesh>.. I just read my earlier  comment.. I really shouldn't drink coffee, eh?... <lol>. Getting my grammar book and resending:

I added the splash screen only to provide eye candy.. because it sounds like you have a lot of things to load before anything is dissplayed to the user. Yes it is superfulous to the question, I was only trying to be helpful if happens to be the situation (long initial load).

The LOAD statements given above will execute synchroniously.. (ie first stement executes completely before the next statement begins). As such.. your form will not appear until the Form.Load method is completed.. and then only when a Form.Show method is executed.

Avatar of Ark
What's about FirstInTabOrderControl_GotFocus?
Cheers
or using Ctl.SetFocus for any control and start function from ctl_GotFocus event?
Is this another version of the "need to capture the screen to save an error condition" question?
One problem I have had, similar to this:  Referencing DAO data controls from the Form_Load event.  Sometimes it works, sometimes it don't.  Our solution was this:

Sub Form_Load()
Dim UselessWaste as control
For Each UselessWaste in Controls
    UselessWaste.Tag = UselessWaste.Tag
Next
Data1.Recordsource = OtherModules_Sql_Statement
Data1.Requery
end sub


Don't know if this exactly rings the bell for you - for us, it made sure every control was loaded enough for us to read & write  the tag property - then we didn't care what zorder that "Data1" was in - it was always loaded when we fired the requery.
 
ok ppl. thank you all.
i've managed to get around it and in case you want to know how - here it is :
1
The goal of all that is to SHOW the user that a very complicated function he activated is being carried out.
although the mission can be carried out in the back - i've decided to make it
visual to the user in such a way that a FORM containg diffrent content will
be Show at the end of each LOOP-ROUND that filling its controls with diffrent data.
since the proccess is long - i wanted to hide that form in the moment it is stable in order not to spend time for nothing.
i did not wanted to do half work and hide the form before it's fully displayed.
that was the background for the question.
2
doing that i've find out that the ACTIVATE event that is the LAST event to be fired as a result of the SHOW command to the form - is fired before the form is completly displayed.
so i've had no indication for the moment the form is fully displayed, and did not know when to hide it.
3
since filling the form's controls and showing it is carried out from other form's code - i tried to capture the desired moment from there :
after the SHOW command i start a LOOP searching for the API GetWindowText , which gives the caption of the Window with the FOCUS.
i've found that it gives the Desired form's caption ONLY WHEN IT'S FULLY DISPLAYED, and here i've nailed the moment. sure i had to add a DoEvents
statment to that loop to enable the form to complete the show operation.
4.
that's works fine on both fast and slow machines.
5.
thanks all again
Foyal : don't understand you last comment
There was a question posted recently where someone wanted to capture the screen if the form loaded in an error condition so as to save a picture of the screen. To me, it made a lot more sense to trap the error and do something about it. But then, without adequate information it's very hard to make judgements. I guess there must be a reason; like I said, it's hard to tell sometimes.
AnswerTheMan,
your trick is interesting. BTW, one thought, did you try Me.Refresh method at the end of form_load event. This method force repainting form and you can use form_activate event after this. I tried it on form with 93 controls - it works.
Cheers
Community Support has reduced points from 200 to 0
ASKER CERTIFIED SOLUTION
Avatar of ianB
ianB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial