Jump to content

Cursor position question


waltv7
 Share

Recommended Posts

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

:)

Link to comment
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

:)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...