VFP 的 InputBox() 函数仅仅允许单行文本,但是,如果需要多行文本,是不是就束手无策了呢?
Eddy Maue 写了一个表单类,称为 EmInputBox。当然,你可能觉得不完美,但是,有源码啊!
**************************************************
*-- Auteur : Eddy Maue
*-- Créer le : 2018-09-02
**************************************************
Define Class clssEMInputBox As Form
AutoCenter= .T.
WindowType= 1 && modal
Top = -1
Left = 0
Height = 108
Width = 289
DoCreate = .T.
Caption = "EmInputBox : cDialogCaption"
cTitre = ""
cCaption = ""
cRetvalue = ""
Name = "Form1"
success = .T.
* --------------------------------------------------------------------------------
Add Object lblPromptInput As Label With ;
AutoSize = .T., ;
Caption = "cInputPrompt ", ;
Height = 17, ;
Left = 5, ;
Top = 12, ;
Width = 78, ;
Name = "lblPromptInput "
* --------------------------------------------------------------------------------
Add Object btnAccept As CommandButton With ;
Top = 72, ;
Left = 107, ;
Height = 27, ;
Width = 84, ;
Anchor = 12, ;
Caption = "确定", ;
Default = .T., ;
Name = "btnAccept"
* --------------------------------------------------------------------------------
Add Object btnAnnuler As CommandButton With ;
Top = 72, ;
Left = 197, ;
Height = 27, ;
Width = 84, ;
Anchor = 12, ;
Cancel = .T., ;
Caption = "取消", ;
Name = "btnAnnuler"
* --------------------------------------------------------------------------------
Add Object edit1 As EditBox With ;
Anchor = 15, ;
Height = 24, ;
Left = 5, ;
ScrollBars = 0, ;
Top = 36, ;
Width = 276, ;
Name = "Edit1"
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
Procedure ccaption_assign
Lparameters tcCaption
Store m.tcCaption To This.cCaption, This.Caption
Endproc
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
Procedure ctitre_assign
Lparameters tcTitre
This.cTitre = tcTitre
This.label1.Caption = tcTitre
Endproc
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
Procedure mAccept
Thisform.cRetvalue = Thisform.edit1.Text
Thisform.Release()
Endproc
Procedure Release
m.gcRetVal = This.cRetvalue
m.glSuccess = This.success
Endproc
Procedure Unload
Endproc
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
Procedure Init
Lparameters tcTitre,tcCaption, tcDefaultValue
Local lsDefault As String
lsDefault = Transform(m.tcDefaultValue)
If Vartype(m.tcCaption)=="C" And Not Empty(m.tcCaption)
This.Caption = m.tcCaption
Endif
If Vartype(m.tcTitre)=="C" And Not Empty(m.tcTitre)
This.lblPromptInput.Caption = m.tcTitre
Endif
If Vartype(m.lsDefault)=="C" And Not Empty(m.lsDefault)
This.edit1.Value = m.lsDefault
Endif
This.edit1.SetFocus()
This.edit1.SelStart = 3000
Endproc
Procedure mAnnuler()
Thisform.QueryUnload()
Endproc
Procedure btnAccept.Click
Thisform.mAccept()
Endproc
Procedure btnAnnuler.Click()
Thisform.mAnnuler()
Endproc
Procedure QueryUnload()
This.success = .F.
Thisform.cRetvalue = ""
Thisform.Release
Endproc
Enddefine
使用也非常的简单:
Set Debug On
success = .T.
lRetVal = EmInputBox("Exemple : MaVariable = 5","Local as string",'ls' ,@success )
Wait Window lRetVal
llsuccess = success
Wait Window "success = "+Transform(success)
* /ˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉˉ EmInputBox
* / Eddy Maue a+ -- Créer le : 2018-09-03
* ----------------------------------------------------------------------------------------
* Wait Window EmInputBox("Exemple : MaVariable = 5","Local as string",'ls' , @success)
Procedure EmInputBox
Lparameters tcTitre,tcCaption, tcDefaultValue , success
Private gcRetVal,glSuccess
m.gcRetVal = ""
glSuccess = success
Local loFrm As Form
loFrm = Createobject("clssEMInputBox",tcTitre,tcCaption, tcDefaultValue)
loFrm.Show(1)
success= glSuccess
Return gcRetVal
Endproc && EmInputBox
未雨绸缪。
Follow me,认识不一样的 VFP !