前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >一个扩展的 InputBox() -- EmInputBox

一个扩展的 InputBox() -- EmInputBox

作者头像
firstxinjie
发布2024-12-06 14:25:52
发布2024-12-06 14:25:52
7800
代码可运行
举报
文章被收录于专栏:X#(XSharp)X#(XSharp)
运行总次数:0
代码可运行

VFP 的 InputBox() 函数仅仅允许单行文本,但是,如果需要多行文本,是不是就束手无策了呢?

Eddy Maue 写了一个表单类,称为 EmInputBox。当然,你可能觉得不完美,但是,有源码啊!

代码语言:javascript
代码运行次数:0
运行
复制
**************************************************
*-- 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

使用也非常的简单:

代码语言:javascript
代码运行次数:0
运行
复制
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 !

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-06-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 xinjie的VFP 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档