July 02, 2024, 03:17:37 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Edit box cursor position

Started by Andy, March 11, 2015, 03:56:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

I've been wondering for a good time now is it posible to place the cursor at the end of some text 
in an edit box?

Example:

I create a simple window.
I have an edit box control
The edit box has the word "IWBasic" in it on creation.

If I set the focus on the edit box the cursor goes before the "I" in IWBasic.
Can you position the cursor after the letter "c" in IWBasic when it gets the focus?

Just curious to see if it can be done, think it might help when editing many edit boxes with text in them.

Thanks,
Andy.
:)


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

March 11, 2015, 05:27:09 AM #1 Last Edit: March 11, 2015, 05:32:19 AM by Egil
Try this:


'
'------------------------------------------------------------------------------
' subroutine to easily append text in an edit control
' by Paul Turley: http://www.ionicwind.com/forums/index.php/topic,3174.0.html
'
' id = the id of the edit control
'------------------------------------------------------------------------------
'
CONST WM_GETTEXTLENGTH = 0xE
Sub AppendEdit(window win,int id,string text,int addNL)
int _textlen:_textlen =SendMessage(win, WM_GETTEXTLENGTH,0,0,id)
ControlCmd win, id, @EDSETSELECTION, _textlen, _textlen
if(addNL)
ControlCmd win, id, @EDREPLACESEL, text + "\n"
else
ControlCmd win, id, @EDREPLACESEL, text
endif
RETURN
ENDSUB


Calling  with an empty string will place the cursor at the end of the edit control.


Good luck!

Egil
Support Amateur Radio  -  Have a ham  for dinner!

Andy

Thanks Egil and of course to Paul,

Yes, doing this:

       AppendEdit(dy,p1,"",0)
       SetFocus dy,p1

Where dy is the window, and p1 is the edit control.

Works great and looks professional!

Thanks to both of you!
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Egil,

Been messing, and came up with this. Does it in two lines, three if you add the SETFOCUS:

WINDOW win

OPENWINDOW win,0,0,300,200,0x80CB0080,0,"Caption",&wHandle
   CONTROL win,@EDIT,"IWBasic is Great!",35,70,186,26,0x50800080,10
   SETFOCUS win,10
   INT length=CONTROLCMD win,10,@EDGETLINELENGTH,-1
   CONTROLCMD win,10,@EDSETSELECTION,length,length

WAITUNTIL IsWindowClosed(win)

SUB wHandle(),INT
   SELECT @MESSAGE
CASE @IDCREATE
   CENTERWINDOW win
CASE @IDCLOSEWINDOW
   CLOSEWINDOW win
ENDSELECT
RETURN 0
ENDSUB

Brian

Egil

That's almost the same as Paul once suggested.
The SUB I posted was copied from my SerialComms Terminal program.
Had to put in the extras to cope with the behaviour of different kinds of modems, to get the logfiles right when woorking with multiline editcontrols, echo on or off in the modem, local echo on or off. And some modems always return an extra newline character.
I usuall make my subs so they can be reused in other applications, and sometimes they look some "strange" to others.... :D

Regards,
Egil

Support Amateur Radio  -  Have a ham  for dinner!