0

I created a modeless form in vfp and set the showwindow properties to '0-in screen'.I placed a button in the form and added 'DO Form Form2' in the click method. Form2 is again a modeless form and the showwindow properties set to '0-in screen'. I run the first form, and clicked the button. The second form appears. The problem is I can't seem to setfocus to /activate the first form, unless I close the second form first. Does it suppose to work that way? if yes, why? Is there any workaround for this situation?

Actually, my scenario is a little bit more complex. i open form1.If I click a button in form1, form2 shows up.Both form are in _screen. If I click another button in form1, Form3 shows up, inside form2.I certainly hope this is possible. :)

Thank You for helping Me.

wong chung yie
  • 175
  • 1
  • 4
  • 14
  • Thank You for your suggestion. I'll keep them in mind. It's just, sometimes, the suggestions are new things that I have never thought of and I want to really try them, so that I don't turn down a good suggestion just because I've found another solution. :) – wong chung yie May 29 '12 at 01:16
  • yes about checking answers, but if they also give you an alternative way of thinking that DOES help, that too should help. OR... you can answer your own question on how YOU solved it and that it is a resolved question for others to not bother trying to re-answer. – DRapp May 29 '12 at 11:20

2 Answers2

1

What you may be encountering is just that the two windows are the same size (or Form 2 is larger) and just physically overlapping form 1... unless both forms are set to maximize mode which takes the full screen viewing area.

That said, by default, when VFP runs a form, it basically has a variable name correlating to your form name... ie: "Form1" and "Form2" if those are the names of your actual forms (which I doubt, but may be for testing purposes).

So, now you are running your sample, form 1 is shown, click button, form 2 is shown. You can have a button on form 2, such as "go back to form 1" (as opposed to re-run another instance of form 1). In the click event of that, you can do the following

if wexist( "form1" )
   activate window form1
endif 

Similarly, in your main form, if you want to go back to form 2 again, but DO NOT want to recreate a second instance of the already open form, you could have that code something like

if wexist( "form2" )
   */ Show the already loaded form
   activate window form2
else
   */ Not loaded yet, do so now
   do form form2
endif 

As for showing one form inside another form, you can, but they can sometimes be a bit of a pain and just some getting used to... They are called "Formsets". To do so, you are basically pre-building all the forms into one overall "formset". Start by creating a single form. Then, from the "FORM" menu item, click the menu option to "Create Form Set". It will create a parent "formset" level for you and move the form itself into the child position. Then, from the "FORM" menu, you can choose "Add New Form" again, and add as many as you need. Note, when doing this, it builds all the forms, not just based on you explicitly doing a "do form" call to launch the next form. You can set titles per window, move the physical positions of them, etc... save and run the form... Then you can show/hide as you need to... but again, can be tricky.

ANOTHER ALTERNATIVE you may try is to work with "containers", and build yourself a class library. A container is nothing but a control that can have other controls. The benefit is that you can build it once and use it as a part of a form, or on multiple forms as needed without having to keep calling the same first form. For example, a container for address information. You may have a label/textbox for Company, Address1, Address2, City, etc and save it. Now, you want to have an invoice that has a ship-to and bill-to on it. You can use two instances of the same "layout" container class on the same form. They look and operate the same, you would just bind "control source" them to respective fields.

By doing this, you can also get into using "tabbed pages" and build a container of all things associated with one "page". Then put that container on the page instead of all controls individually all in one form... Takes more time up-front, but down-stream management can be a benefit too.

DRapp
  • 47,638
  • 12
  • 72
  • 142
  • I made sidepanel for my project (like the one in the control panel).The form1 I mentioned earlier is the sidepanel. I used form2, because I can set the size and position of both form1 and form2, and prevent them fom being rezised. I, then, want to open form3 in form2, so that when form3 is maximized, it only fill the form2 area, instead of the whole screen. Thank you for the reply. – wong chung yie May 29 '12 at 01:00
-1

if u have two forms modedeless u can try make one app with the second form with a prg to intermediate the paremeter statement. sample:** in ther first form method to call second:**

LOCAL  cvar

cvar="F_"+ALLTRIM(TRANSFORM(SYS(3)))

PUBLIC &cvar

&cvar=THISFORM && instance the first form in a public var (dont forget relese this in unload methode)

DO secondform.app WITH cvar

thisform.hide

in second form prg main :

PARAMETERS xparform

IF PARAMETERS() = 1

      DO FORM secondform WITH xparform

   endif 

in second form.

create property to contain the parameter

in init method:

PARAMETERS xparsecod

IF PARAMETERS() > 0

    IF PARAMETERS() = 1

     thisform.formfirst=xparsecod

   endif

endif 

in Unload :

IF !EMPTY(thisform.formfirst)

    LOCAL cprince,oprince

    cprince=ALLTRIM(thisform.formfirst)

    oprince=&cprince && instanciate the firsform object

    IF TYPE("oprince")=="O"

       oprince.show && show the first form 

       oprince=null

    ENDIF 

ENDIF        
thisform.Release

this force the second form to show the firsrt form after done dont forget to release the public var

try some like:

if type("namevar") <> "U"

   namevar=null

   release namevar

endif 
Pranit Kothari
  • 9,721
  • 10
  • 61
  • 137