Simulates "Set Confirm Off" and Overwrite in TextBoxes
Posted: Sun Mar 23, 2014 1:47 am
This improved example was extracted from this post of Toledo forum which I believe could it be usefull and we wish to share with you.
This demo when editing and fill TextBox will change focus to next field. Also can be use overwrite editing but works only when is TEXT and with no mask in it.
I hope you enjoy it !
Code: Select all
#include <hmg.ch>
Function Main()
SET NAVIGATION EXTENDED
SET DATE TO BRITISH
SET CENTURY ON
DEFINE WINDOW Form_1 AT 0,0 ;
WIDTH 400 HEIGHT 175 NOSIZE ;
TITLE 'Simulating SET CONFIRM OFF at TextBoxes' ;
MAIN
ON KEY ESCAPE ACTION ThisWindow.Release()
DEFINE STATUSBAR FONT "Courier New" SIZE 9
STATUSITEM PadC("Press <Insert> key and type again",44)
STATUSITEM " Insert" WIDTH 94 ICON if ( IsInsertActive() , "zzz_led_off" , "zzz_led_on" )
END STATUSBAR
DEFINE LABEL Label_1
ROW 20
COL 30
WIDTH 160
VALUE 'Field 1 (Length 10):'
FONTBOLD .T.
END LABEL
DEFINE TEXTBOX Text_1
ROW 20
COL 160
WIDTH 180
MAXLENGTH 10
ON CHANGE {|| SetConfOFF(10,0) }
END TEXTBOX
DEFINE LABEL Label_2
ROW 48
COL 30
WIDTH 160
VALUE 'Field 2 (Length 10):'
FONTBOLD .T.
END LABEL
DEFINE TEXTBOX Text_2
ROW 48
COL 160
WIDTH 180
MAXLENGTH 10
DATE .T.
ON CHANGE {|| SetConfOFF(10,0) }
END TEXTBOX
DEFINE LABEL Label_3
ROW 76
COL 30
WIDTH 160
VALUE 'Field 3 (Length 14):'
FONTBOLD .T.
END LABEL
DEFINE TEXTBOX Text_3
ROW 76
COL 160
WIDTH 180
INPUTMASK "999.999.999-99"
ON CHANGE {|| SetConfOFF(0,Len("999.999.999-99")) }
END TEXTBOX
_DefineTimer ( 'StatusKeyBrd' , "Form_1" , 50 , ;
{|| _SetStatusIcon ( 'StatusBar' , "Form_1" , 2 , if ( IsInsertActive() , "zzz_led_off" , "zzz_led_on" ) ) } )
END WINDOW
CREATE EVENT PROCNAME OnkeyAllEditBox()
Form_1.Center
Form_1.Activate
Return Nil
Function SetConfOFF( nMaxLength, nInputMask )
Local cFrmName := ThisWindow.Name
Local cCmpName := This.FocusedControl
If nInputMask > 0
nMaxLength := nInputMask
Endif
If !Empty(cCmpName)
If nMaxLength == GetProperty(cFrmName,cCmpName,"CaretPos")
InsertTab()
Endif
Endif
Return Nil
Function OnkeyAllEditBox()
Local nIndex := GetControlIndexByHandle (EventHWND())
If nIndex > 0 .AND. GetControlTypeByIndex (nIndex) == "TEXT"
If EventMSG() == WM_CHAR
If .NOT. (GetKeyState (VK_INSERT) == 0) .AND. HMG_GetLastVirtualKeyDown() != VK_RETURN .AND. HMG_GetLastVirtualKeyDown() != VK_BACK
SendMessage (EventHWND(), WM_KEYDOWN, VK_DELETE, 0)
KSETINS(.T.)
Else
KSETINS(.F.)
Endif
Endif
Endif
Return NIL
I hope you enjoy it !