How can I position the cursor within an editbox

Author: hartmut.link@arcor.de (hartmut.link)

Hello,

does anybody know, how I can position the cursor within a multiline editbox ?

for example:

end of text, end of line, next line.

 

Thanks

 

5 Comments

  1. Hallo Hartmut,

     

    If I remember it well (tried it a long long time ago) the uniface macro statements works only in unifields.

    Think I saw somwehere (in the undocumented features channels) there is a way to position the cursor
    perhaps with fieldproperties or something similar.

     

    Sometimes, one can abuse the "find" to go to the next line or so, but this is crippleware path of professionalism

     


    Author: ulrich-merkel (ulrichmerkel@web.de)
  2. Hi, has someone a solution to position the cursor at the end of a RichEditBox? Regards RogerW.


    Author: rogerw (roger.wallin@abilita.fi)
  3. rogerw said Hi, has someone a solution to position the cursor at the end of a RichEditBox? Regards RogerW.  

    Hi RogerW, You could use the Windows USER32 function SendMessage for this. By sending the message EM_SETSEL to the RichEditBox widget you can set the position of the cursor and with the message EM_SCROLLCARET you can make sure that the cursor is visible (i.e. scrolls the cursor position into view). In order to send a message to a widget you need to obtain its window handle you can use the GetFocus function (that will retrieve the handle of the window that has the focus). You can call the mentioned USER32 functions using  C Call-Out signatures. The required code would look like this:

    newinstance "USER32", hUser32 hWnd = hUser32->GetFocus() hUser32->SendMessage(hWnd, <EM_SETSEL>, -1, -1) ; constant EM_SETSEL = 177 hUser32->SendMessage(hWnd, <EM_SCROLLCARET>, 0, 0) ; constant EM_SETSEL = 183

    I’ve created a small sample that demonstrates the above code in "action" (see the Community Sample "Set cursor position in RichEditBox"). The sample includes the form CURSOR1 and the C Call-Out signature USER32. The form features two buttons (one to add text to the RichEditBox field and one to set the cursor). The above code can be found in the Asynchronous Interrupt trigger of the form and it's triggered from the Field Gets Focus trigger. Please note that I’ve created this sample using Uniface 9.7.03. But it should also work with any other Uniface 9.7 or 9.6 version. Hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  4. Thanks Daniel, we will try it soon. I didn't expect an answer on this question Surprised. Regards RogerW.


    Author: rogerw (roger.wallin@abilita.fi)
  5. Hi Daniel, Nice, very nice! As soon as I discovered this small example, I've immediately found a real usage scenario! but ... I can't live on bread alone! Is it also possible to mark a piece of text, like a character or a word or a line or from char 10 to char 20? ...and having also the option to choose backgroud color is asking too much? Gianni


    Author: gianni (gianni.sandigliano@unifacesolutions.com)