Textbox and Cursor Position

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Textbox and Cursor Position

Post by Karl »

Hi all,

maybe that my problem has long been solved but as a beginner I tried all and found no solution.

Code: Select all

//Testprogram Mouseclick in Textbox

#include "hmg.ch"

PROCEDURE main()

DEFINE WINDOW form_1 ;
	  AT 0,0 ;
	  WIDTH 600 ;
	  HEIGHT 230 ;
	  FONT 'Arial' SIZE 9 ;
	  TITLE '   Test Program for TextBoxes' ;
          MAIN
	
@  60,20  LABEL label_1 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 300 ;
          VALUE "Textbox-1 (3 x alpha-Char. and Upper)" ;
          FONT 'Arial' SIZE 12
          
@  60,370 TEXTBOX text_1 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 60 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12;
          INPUTMASK 'AAA' ;
	  ON CHANGE {||THIS.VALUE := HMG_UPPER(THIS.VALUE)}
	
@  90,20  LABEL label_2 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 300 ;
          VALUE "Textbox-2 (4 x numeric-Characters)" ;
          FONT 'Arial' SIZE 12

@  90,370 TEXTBOX text_2 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 60 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12 ;
          INPUTMASK '9999'
          
@ 120,20  LABEL label_3 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 350 ;
          VALUE "Textbox-3 (17 x alphanumeric Char. and Upper)" ;
          FONT 'Arial' SIZE 12
          
@ 120,370 TEXTBOX text_3 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 200 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12 ;
          INPUTMASK '!!!!!!!!!!!!!!!!!'
	
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1

RETURN Nil
in my example there are 3 different textboxes. If you enter one of these textboxes with a mouseclick, the cursor doesn´t stand at the beginning (left edge) of the box. In order to achieve this, I must aim perfectly. This is too time consuming for the user.
My second problem is in Textbox-1 with UPPERCASE instead of ON CHANGE. (I only want uppercase alpha-characters). Somebody an idea to solve it ?
THX Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Textbox and Cursor Position

Post by KDJ »

Hi Karl

This is solution of the first problem:

Code: Select all

//Testprogram Mouseclick in Textbox

#include "hmg.ch"

PROCEDURE main()

DEFINE WINDOW form_1 ;
	  AT 0,0 ;
	  WIDTH 600 ;
	  HEIGHT 230 ;
	  FONT 'Arial' SIZE 9 ;
	  TITLE '   Test Program for TextBoxes' ;
          MAIN
	
@  60,20  LABEL label_1 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 300 ;
          VALUE "Textbox-1 (3 x alpha-Char. and Upper)" ;
          FONT 'Arial' SIZE 12
          
@  60,370 TEXTBOX text_1 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 60 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12;
          INPUTMASK 'AAA' ;
	  ON CHANGE {||THIS.VALUE := HMG_UPPER(THIS.VALUE)}
	
@  90,20  LABEL label_2 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 300 ;
          VALUE "Textbox-2 (4 x numeric-Characters)" ;
          FONT 'Arial' SIZE 12

@  90,370 TEXTBOX text_2 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 60 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12 ;
          INPUTMASK '9999'
          
@ 120,20  LABEL label_3 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 350 ;
          VALUE "Textbox-3 (17 x alphanumeric Char. and Upper)" ;
          FONT 'Arial' SIZE 12
          
@ 120,370 TEXTBOX text_3 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 200 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12 ;
          INPUTMASK '!!!!!!!!!!!!!!!!!'
	
END WINDOW

EventCreate("Edit_LBUTTONUP", form_1.text_1.HANDLE, 514 /*WM_LBUTTONUP*/)
EventCreate("Edit_LBUTTONUP", form_1.text_2.HANDLE, 514 /*WM_LBUTTONUP*/)
EventCreate("Edit_LBUTTONUP", form_1.text_3.HANDLE, 514 /*WM_LBUTTONUP*/)

CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1

RETURN Nil


FUNCTION Edit_LBUTTONUP()

  HMG_EditControlSetSel(EventHWND(), 0, 0)

RETURN NIL
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Textbox and Cursor Position

Post by serge_girard »

Thanks Krysztof !

I had the same problem and had to live with it...

Serge
There's nothing you can do that can't be done...
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox and Cursor Position

Post by franco »

kdj, I have not found how to use the keyboard() function in hmg but.
If you know it you could try in text_1 ..... on gotfocus keyboard(chr29)) ... or onmouseclick keyboard(chr(29))
Let me know, if you know how to use keyboard command and if this works, for I have same problem.
Franco
All The Best,
Franco
Canada
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Textbox and Cursor Position

Post by Karl »

KDJ wrote: Fri Jun 16, 2017 2:37 pm Hi Karl
This is solution of the first problem:
Hi Krysztof, this is a great help for me and thanks a lot !
I´ll apply your changes in many textboxes because it is a great time progress. But not in all, because it changes the behaviour of marking and changing. E.g. when you are in the thirteenth textbox and notice, that you must change something in the first one, the cursor always jumps to the first position. But somehow it´s a fine solution. :)
Kind regards Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
franco
Posts: 816
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Textbox and Cursor Position

Post by franco »

I do not know how create events work but could you make the event work only when textbox is empty
Franco.
All The Best,
Franco
Canada
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Textbox and Cursor Position

Post by Karl »

franco wrote: Fri Jun 16, 2017 10:24 pm could you make the event work only when textbox is empty
you noticed the same as I. If Krysztof could fulfill this wish would be the absolute top.
Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Textbox and Cursor Position

Post by KDJ »

Karl wrote: Sat Jun 17, 2017 5:16 am
franco wrote: Fri Jun 16, 2017 10:24 pm could you make the event work only when textbox is empty
you noticed the same as I
Karl and Franco

I do not quite understand. Please describe in more detail.
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Textbox and Cursor Position

Post by Karl »

KDJ wrote: Sat Jun 17, 2017 8:18 pm I do not quite understand. Please describe in more detail.
Hi Krysztof, Franco, Serge,
I don´t know anything about EventCreate and HMG_EditControlSetSel but made changes in Krysztof´s code. Now if you are ON GOTFOCUS or ON LOSTFOCUS the behavior of the TextBox will change. In my example the cursor is standing at the right edge of the textbox if it contains text and you enter it once again. This is not yet perfect. It would be perfect if the behavior of ON LOSTFOCUS would fully cancel the command HMG_EditControlSetSel. ;)
Karl

Code: Select all

//Testprogram Mouseclick in Textbox

#include "hmg.ch"

PROCEDURE main()

DEFINE WINDOW form_1 ;
	  AT 0,0 ;
	  WIDTH 600 ;
	  HEIGHT 230 ;
	  FONT 'Arial' SIZE 9 ;
	  TITLE '   Test Program for TextBoxes' ;
          MAIN
	
@  60,20  LABEL label_1 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 300 ;
          VALUE "Textbox-1 (3 x alpha-Char. and Upper)" ;
          FONT 'Arial' SIZE 12
          
@  60,370 TEXTBOX text_1 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 60 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12;
          INPUTMASK 'AAA' ;
	  ON CHANGE {||THIS.VALUE := HMG_UPPER(THIS.VALUE)} ;
          ON GOTFOCUS {||IF(THIS.VALUE = " ", EventCreate("Edit_LBUTTONUP", form_1.text_1.HANDLE, 514), '')} ;
          ON LOSTFOCUS {||IF(THIS.VALUE != NIL , EventCreate("Edit_LBUTTONDOWN", form_1.text_1.HANDLE, 514), '')}
	
@  90,20  LABEL label_2 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 300 ;
          VALUE "Textbox-2 (4 x numeric-Characters)" ;
          FONT 'Arial' SIZE 12

@  90,370 TEXTBOX text_2 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 60 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12 ;
          INPUTMASK '9999' ;
          ON GOTFOCUS {||IF(THIS.VALUE = " ", EventCreate("Edit_LBUTTONUP", form_1.text_2.HANDLE, 514), '')} ;
          ON LOSTFOCUS {||IF(THIS.VALUE != NIL , EventCreate("Edit_LBUTTONDOWN", form_1.text_2.HANDLE, 514), '')}          
          
@ 120,20  LABEL label_3 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 350 ;
          VALUE "Textbox-3 (17 x alphanumeric Char. and Upper)" ;
          FONT 'Arial' SIZE 12
          
@ 120,370 TEXTBOX text_3 OF form_1 ;
          HEIGHT 20 ;
          WIDTH 200 ;
          VALUE '' ;
          FONT 'Arial' SIZE 12 ;
          INPUTMASK '!!!!!!!!!!!!!!!!!' ;
          ON GOTFOCUS {||IF(THIS.VALUE = " ", EventCreate("Edit_LBUTTONUP", form_1.text_3.HANDLE, 514), '')} ;
          ON LOSTFOCUS {||IF(THIS.VALUE != NIL , EventCreate("Edit_LBUTTONDOWN", form_1.text_3.HANDLE, 514), '')}
	
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
RETURN Nil

FUNCTION Edit_LBUTTONUP()
  HMG_EditControlSetSel(EventHWND(), 0, 0)
RETURN NIL

FUNCTION Edit_LBUTTONDOWN()
  HMG_EditControlSetSel(EventHWND(), 17, 17)
RETURN NIL
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Textbox and Cursor Position

Post by serge_girard »

Thanks all!

Serge
There's nothing you can do that can't be done...
Post Reply