Sign in to follow this  
Followers 0
waltv7

Cursor position question

3 posts in this topic

Hello again. I need to make the curson in the editbox move to the end of the text is there a way to do this and if so how?

Thanks in advance Walt

Share this post


Link to post
Share on other sites



Example:

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>

$sRead = FileRead(@ProgramFilesDir & "\AutoIt3\Include\ChangeLog.txt")

$hGUI = GUICreate("Test", 300, 200)

$cEdit = GUICtrlCreateEdit("", 10, 10, 280, 150)
GUICtrlSetData(-1, $sRead)

$ScrollButton = GUICtrlCreateButton("Scroll", 11, 168, 75, 23)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ScrollButton
            _TextScroll($cEdit)
    EndSwitch
WEnd

Func _TextScroll($cCtrl)
    Local $iCount = GUICtrlSendMsg($cCtrl, $EM_GETLINECOUNT, 0, 0)
    Local $iIndex = GUICtrlSendMsg($cCtrl, $EM_LINEINDEX, $iCount - 1, 0)
    
    GUICtrlSetState($cCtrl, $GUI_FOCUS)
    
    GUICtrlSendMsg($cCtrl, $EM_SETSEL, $iIndex, $iIndex)
    GUICtrlSendMsg($cCtrl, $EM_LINESCROLL, 0, $iCount)
EndFunc   ;==>_TextScroll

:)

Share this post


Link to post
Share on other sites

This example shows how to set caret and scroll the line to the caret position:

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <GUIEdit.au3>

$sRead = FileRead(@ProgramFilesDir & "\AutoIt3\Include\ChangeLog.txt")

$hGUI = GUICreate("Test", 300, 200)

$cEdit = GUICtrlCreateEdit("", 10, 10, 280, 150)
GUICtrlSetData(-1, $sRead)

$ScrollButton = GUICtrlCreateButton("Scroll", 11, 168, 75, 23)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ScrollButton
            $iLine = Number(InputBox("Caret position", "Enter the line number", 1))
            If (@error = 0) And (IsNumber($iLine) = 1) Then _TextScroll($cEdit, $iLine)
    EndSwitch
WEnd

Func _TextScroll($cCtrl, $iLine)
    Local $iIndex = GUICtrlSendMsg($cCtrl, $EM_LINEINDEX, $iLine, 0)
    If $iIndex = -1 Then Return 0
    
    GUICtrlSetState($cCtrl, $GUI_FOCUS)
    
    GUICtrlSendMsg($cCtrl, $EM_LINESCROLL, 0, $iLine)
    GUICtrlSendMsg($cCtrl, $EM_SETSEL, $iIndex, $iIndex)
EndFunc   ;==>_TextScroll

:)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0