Link to home
Start Free TrialLog in
Avatar of oldbie
oldbie

asked on

problem with a hidden form

I have an app with four different forms, three of which are usually not displayed (configuration forms). When the user changes a text field on the main form, I need to update a value on a hidded configuration form, so it's correct when the user opens it. But in the frmMain code, when I say something like

frmConfig.actualPosition.text = actualPos

frmConfig becomes visible. The best I've done so far is to immediately hide it again after stuffing the data in it, but I know there must be an easy way to update a forms fields without showing the form. (If it turns out not to be easy, but you know the answer, I'll tack on some extra points.)

Thanks.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

This means that your configuration form was not loaded yet, thus loading it as soon as you change one of the properties that makes the form issue some painting.
What you need is to load your forms at startup:

---- frmMain.frm ---
private mfrmConfig1 as frmConfig1

Private Sub Form_Load()
  set mfrmConfig1 = new frmConfig1
  'do be sure the form doesn't show
 mfrmConfig1.Visible = false
End sub

Private Sub Form_Unload()
  unload mfrmConfig
  set mfrmConfig = Nothing
End Sub

--------------------
If now you update the property on your form, it won't show up.

Don't worry about points. Real Experts are here to help :-)


Avatar of Nazdor
Nazdor

AngelIII is correct here, but it's slightly easier - there's no need to create a variable to hold the form, unless you want to open the same form more than once.  So in your main form:

Private Sub Form_Load()
    Load frmConfig
End Sub

Private Sub Form_Unload()
    Unload frmConfig
End Sub


Then, when you want the form to be visible, simply: frmConfig.Visible = true

You must unload any loaded forms though.


The other thing to remember is that when frmConfig tries to close, it mustn't actually close - merely become visible=false, so in frmConfig you also need:

Private Sub Form_Unload(Cancel As Integer)
    Me.Visible = False
    Cancel = True
End Sub


Otherwise you'll be back to where you were before with the second time the form gets accessed it pops up.

Perhaps that's where using a variable will help - not tried it out.


---

The alternative would be to load your settings in the Form_Load of frmConfig so that you're not continuously copying data across, just once when the form loads.  But I doubt there's much of a performance difference either way.
Have you tried with
frmConfig.Visible=False
before you do
frmConfig.actualPosition.text = actualPos

This should be enough.
If the Program is a MDI form and has MDI children you need to go to the main MDI form and turn off the property Autoshowchildren.

Just a thought.
Avatar of oldbie

ASKER

Something that might not have been clear: frmConfig can be visible or not, by the user's choice, and I need to update the field either way.

Loading the form in frmMain's Load and then hiding it makes frmConfig flash visible and then disappear. Looks unprofessional. And I'm getting paid for this, so I'm a professional, right? hmmm.

So, to refine the problem description: The main form has a button which displays the config forms. The config forms have fields on them that need to be updated as the situation in the external world changes, whether or not those config forms are displayed at the moment, so that when they are displayed, the data will be correct. And I don't want any forms flashing for a split-second as they're loaded and then hidden.

Thanks for your help!
ASKER CERTIFIED SOLUTION
Avatar of wsh2
wsh2

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
wsh2: i think that you are wrong.
if a form was not loaded, and you issue a change to one of the properties that need painting, the form will load AND show (if visible property is set true as default) Try it (smile)
Avatar of oldbie

ASKER

wsh2, you are right. (I'll bet it's fun to always be right!)

Poltergeists snuck a Me.Show into the form load sub. I took it out and everything works like it should.

When I think of the time I wasted looking in all the wrong places .... <sigh>

Thanks. Have some points.

~~~~~~~~~~~~~

angelIII, you are wrong. Try it. I did.

Form1 with two buttons:

Private Sub Command1_Click()
  ' put date and time in text box on other form
  frmOther!Text1.Text = Now
End Sub

Private Sub Command2_Click()
  frmOther.Show
End Sub

frmOther with a lonely text box, saying "Text1".

Run the prog, click command1 button. Nothing (visible) happens. Click command2 button. Text box magically has current date and time in it.

oldbie.. Thank you for the always right compliment.. I am a "MAN" afterall.. <running and ducking from AngelIII.. lol.. just kidding>.

Changing a textbox is not necessarily a good test of what AngelIII is purporting, as there is no repaint involved. Now that I am here.. I guess I should check it out. Be Right Back.. <smile>. Ok.. I added a Form2.Move statement in Form1.. and then added a Form2.Circle method after that.. and executed the code with Form2 Autodraw = to True and then False.. Form2 never appeared.. as it should not.

Now, in all fairness, I am using VB6(SP3) on a Win95 PC to test this. Perhaps with a different version of VB or different Operating system environment the behaviour that AngelIII alludes to, will happen.. it just didn't happen here.

Having visited with AngelIII in other threads, she seems to be a very knowledgable Expert.. as such, I have always held her comments in high regard.. <smile>.
Hi wsh2, commenting the "SHE", but ... I'm a "MAN" too (grin)
I'will check my previous comment regarding the form behaviour...

CUL8R
AngelIII:
What MAN is an "Angel" when it comes to Form and Behaviour?... <lol> and a <smile>.