Cythor Posted November 11, 2013 Share Posted November 11, 2013 Hello people. I need the Line Number of the Cursor in a Edit Control. But I haven't a idea how I can do that. I need a idea or a beginning for my problem. I hope you can help me. Cythor =) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 11, 2013 Moderators Share Posted November 11, 2013 Cythor,This should give you the idea: expandcollapse popup#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 WEndPlease ask if you have any questions? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Cythor Posted November 11, 2013 Author Share Posted November 11, 2013 (edited) Smart 8| Thank you very much for the code. I will write the Line Numbers left of the Edit Control. But the GUI is to little for long texts. The rest can I do alone. Cythor =D Edited November 11, 2013 by Cythor Link to comment Share on other sites More sharing options...
martin Posted November 16, 2013 Share Posted November 16, 2013 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 More sharing options...
Moderators Melba23 Posted November 16, 2013 Moderators Share Posted November 16, 2013 Cythor and martin,I have this in my snippets folder if it is any help: expandcollapse popup#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 EndFuncM23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now