0

我在 vfp 中创建了一个无模式表单并将 showwindow 属性设置为“0-in screen”。我在表单中放置了一个按钮,并在 click 方法中添加了“DO Form Form2”。Form2 又是一个无模式窗体,并且显示窗口属性设置为“0-in screen”。我运行第一个表单,然后单击按钮。出现第二种形式。问题是我似乎无法将焦点设置为/激活第一个表单,除非我先关闭第二个表单。它应该这样工作吗?如果是,为什么?这种情况有什么解决方法吗?

实际上,我的情况要复杂一些。我打开form1。如果我单击form1 中的按钮,会显示form2。两种形式都在_screen 中。如果我单击 form1 中的另一个按钮,Form3 会出现在 form2 中。我当然希望这是可能的。:)

感谢你们对我的帮助。

4

2 回答 2

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.

于 2012-05-28T12:58:54.373 回答
-1

如果您有两种无模式的表单,您可以尝试使用第二种表单制作一个应用程序,并使用 prg 来中间参数语句。示例:** 在第一种形式的方法中调用第二种:**

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

在第二种形式 prg main :

PARAMETERS xparform

IF PARAMETERS() = 1

      DO FORM secondform WITH xparform

   endif 

在第二种形式。

创建属性以包含参数

在初始化方法中:

PARAMETERS xparsecod

IF PARAMETERS() > 0

    IF PARAMETERS() = 1

     thisform.formfirst=xparsecod

   endif

endif 

在卸载:

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

这会强制第二种形式在完成后显示第一种形式不要忘记发布公共 var

尝试一些像:

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

   namevar=null

   release namevar

endif 
于 2014-08-31T01:34:56.083 回答