Jump to content

Edit Control - Get Line Cursor


Cythor
 Share

Recommended Posts

  • Moderators

Cythor,

This should give you the idea: ;)

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>

Global $aLocation[2] = [0, 0]

$sText = "This is a long pice of text which should require wrapping in the edit control - " & _
        "which is provided by the combination of $ES_WANTRETURN and $ES_MULTILINE styles"

$hGUI = GUICreate("Test", 500, 500)

$cEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200, BitOR($ES_WANTRETURN, $ES_MULTILINE))

$cButton_Locate = GUICtrlCreateButton("Locate", 10, 300, 80, 30)
$cButton_Reset = GUICtrlCreateButton("Reset", 10, 350, 80, 30)
$cButton_Relocate = GUICtrlCreateButton("Relocate", 10, 400, 80, 30)

$cLabel_Line = GUICtrlCreateLabel("Line: ", 100, 300, 100, 20)
$cLabel_Col = GUICtrlCreateLabel("Col: ", 200, 300, 100, 20)

GUISetState()

; Set cursor to start
_GUICtrlEdit_SetSel($cEdit, 0, 0)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Locate
            ; Show and save current position
            GUICtrlSetData($cLabel_Line, "Line: " & ControlCommand($hGUI, "", $cEdit, "GetCurrentLine", ""))
            GUICtrlSetData($cLabel_Col, "Col: " & ControlCommand($hGUI, "", $cEdit, "GetCurrentCol", ""))
            ; Get current position in usable form
            $aLocation = _GUICtrlEdit_GetSel($cEdit)
            GUICtrlSetState($cEdit, $GUI_FOCUS)
        Case $cButton_Reset
            ; Reset cursor to start
            GUICtrlSetState($cEdit, $GUI_FOCUS)
            _GUICtrlEdit_SetSel($cEdit, 0, 0)
        Case $cButton_Relocate
            ; Relocate cursor to stored position
            GUICtrlSetState($cEdit, $GUI_FOCUS)
            _GUICtrlEdit_SetSel($cEdit, $aLocation[0], $aLocation[1])
    EndSwitch

WEnd
Please ask if you have any questions? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If the edit has scroll bars for longer text then writing the line numbers to the left will require that you write the line numbers in another edit and synchronise the scrolling. I did an example for that somewhere so if you need that I will try to find it, otherwise I am happy to do nothing.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Cythor and martin,

I have this in my snippets folder if it is any help: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#Include <GuiEdit.au3>
#Include <Misc.au3>

Global $g_iMainLineCount = 0 ; Keep a global count so we can check if it has changed

$hGUI = GUICreate("Form1", 200, 200, Default, Default, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$cEdit_Num = GUICtrlCreateEdit("", 10, 10, 30, 163, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_RIGHT), 0)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetData($cEdit_Num, "1")
GUICtrlSetBkColor($cEdit_Num, 0xC0DCC0)
GUICtrlSetResizing($cEdit_Num, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
$cEdit_Main = GUICtrlCreateEdit("", 40, 10, 150, 180, -1, 0)
GUICtrlSetResizing($cEdit_Main, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
$cLabel = GUICtrlCreateLabel("", 10, 173, 30, 17)
GUICtrlSetBkColor($cLabel, 0xC0DCC0)
GUICtrlSetResizing($cLabel, $GUI_DOCKSTATEBAR + $GUI_DOCKLEFT + $GUI_DOCKWIDTH) ; $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH)
GUISetState(@SW_SHOW)

AdlibRegister("_LineNum", 111)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _LineNum() ; line numbering
    Local $iCount = _GUICtrlEdit_GetLineCount ($cEdit_Main)

    ;Check if the number of lines has changed in $cEdit_Main
    ;since this function was last called
    If $iCount <> $g_iMainLineCount Then
        ;save the new count to the global variable
        $g_iMainLineCount = $iCount
        Local $iNumCount = _GUICtrlEdit_GetLineCount ($cEdit_Num)
        If $g_iMainLineCount > $iNumCount Then
            For $i = $iNumCount + 1 To $g_iMainLineCount
                _GUICtrlEdit_AppendText ($cEdit_Num, @CRLF & $i)
            Next
        ElseIf $g_iMainLineCount < $iNumCount Then
            $text = GUICtrlRead($cEdit_Num)
            For $i = $iNumCount To $g_iMainLineCount + 1 Step -1
                $text = StringReplace($text,@CRLF & $i,"")
            Next
            GUICtrlSetData($cEdit_Num, $text)
        EndIf
    EndIf
    Local $iFirstVisMain = _GUICtrlEdit_GetFirstVisibleLine ($cEdit_Main)
    Local $iFirstVisNum = _GUICtrlEdit_GetFirstVisibleLine ($cEdit_Num)
    If $iFirstVisMain <> $iFirstVisNum Then
        _GUICtrlEdit_LineScroll($cEdit_Num, 0, $iFirstVisMain - $iFirstVisNum)
    EndIf
EndFunc
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...