qwert Posted January 31, 2014 Share Posted January 31, 2014 I have a special situation where a text field is normally only one line. But every now and then, it needs to hold several lines ... up to a couple of paragraphs. Is there such a thing as an expanding text field? — one that can expand downward as additional lines are typed in? (see attached) I see this kind of thing all the time in programmed applications. But I can't spot any reference or example for AutoIt3. Here's the code for my simple example: #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $hGui, $hRichEdit, $iMsg $hGui = GUICreate("Example ", 320, 320, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is the first field.", 10, 10, 300, 20, $ES_MULTILINE) GUISetState() While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndSelect WEnd Thanks in advance for any pointers on a direction to take with this. Link to comment Share on other sites More sharing options...
mikell Posted February 1, 2014 Share Posted February 1, 2014 Melba's StringSize UDF does exactly what you want : http://www.autoitscript.com/forum/index.php?showtopic=114034 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2014 Moderators Share Posted February 1, 2014 qwert,Or you can do it like this: #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> $hGUI = GUICreate("Test", 500, 500) $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "This is the first field.", 10, 10, 300, 20, $ES_MULTILINE) GUISetState() Global $iCurrCount = _GUICtrlRichEdit_GetLineCount($hRichEdit) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If _GUICtrlRichEdit_IsModified($hRichEdit) Then _CheckRichEditLineCount() EndIf WEnd Func _CheckRichEditLineCount() Local $iCount = _GUICtrlRichEdit_GetLineCount($hRichEdit) If $iCount <> $iCurrCount Then WinMove($hRichEdit, "", Default, Default, Default, 7 + ($iCount * 13)) $iCurrCount = $iCount EndIf _GUICtrlRichEdit_SetModified($hRichEdit, False) EndFunc ;==>_CheckRichEditLineCountI derived the values for thw new height empirically - no doubt you could determine them programatically if required. 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...
qwert Posted February 1, 2014 Author Share Posted February 1, 2014 Melba, thanks you for your suggestion. It does accomplish what I requested ... and in a forthright way. However, I spent the morning running ALL the examples of your StringSize, GUIExtender and GUIFrame UDFs. Very impressive work! Now I see that there are many more possibilities ... which has led me to consider an even better implementation. (See prototype, below.) Do you have a suggestion on how to make a field expand only if it is selected? My initial impression is that I could do it with the GUIExtender features, but that the result would be a shift effect, not an overlay effect. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2014 Moderators Share Posted February 1, 2014 qwert,More complex than I thought it would be. And how do you intend selecting a RichEdit which becomes hidden under one which has extended? 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...
qwert Posted February 1, 2014 Author Share Posted February 1, 2014 Yes, I didn't mention that. My idea is that a field would expand only when it was selected ... and then revert to a one-line field when any other field (or no field) was selected. It would behave about like a drop-down selection for state or country ... but it would allow key entry. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2014 Moderators Share Posted February 1, 2014 (edited) qwert,I have run into 2 problems: - 1. Lower RichEdit controls appear through the expanded one.- 2. These "hidden" edit controls cannot be reselected.expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WinAPI.au3> Global $aRichEdit[4][2] = [[0, 1], [0, 1], [0, 1], [0, 1]] Global $hLast_Focus = 9999 $hGUI = GUICreate("Test", 500, 500) $aRichEdit[0][0] = _GUICtrlRichEdit_Create($hGUI, "This is the first field.", 10, 10, 300, 20, $ES_MULTILINE) $aRichEdit[1][0] = _GUICtrlRichEdit_Create($hGUI, "This is the second field.", 10, 40, 300, 20, $ES_MULTILINE) $aRichEdit[2][0] = _GUICtrlRichEdit_Create($hGUI, "This is the third field.", 10, 70, 300, 20, $ES_MULTILINE) $aRichEdit[3][0] = _GUICtrlRichEdit_Create($hGUI, "This is the fourth field.", 10, 100, 300, 20, $ES_MULTILINE) $cButton = GUICtrlCreateButton("Test", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $hCurr_Focus = _WinAPI_GetFocus() For $i = 0 To 3 If $hCurr_Focus = $aRichEdit[$i][0] Then _CheckRichEditLineCount($i) ExitLoop EndIf Next ; If none focused If $i = 4 And $hCurr_Focus <> $hLast_Focus Then ConsoleWrite("Resetting Last" & @CRLF) ; Reset last focused control WinMove($hLast_Focus, "", Default, Default, Default, 20) $hCurr_Focus = $hLast_Focus EndIf WEnd Func _CheckRichEditLineCount($iIndex) ; Reset last focused control if not the same If $hLast_Focus <> $aRichEdit[$iIndex][0] Then ConsoleWrite("Resetting " & $iIndex & @CRLF) WinMove($hLast_Focus, "", Default, Default, Default, 20) $hLast_Focus = $aRichEdit[$iIndex][0] EndIf ; Get count of current Local $iCount = _GUICtrlRichEdit_GetLineCount($aRichEdit[$iIndex][0]) If $iCount <> $aRichEdit[$iIndex][1] Then WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, 7 + ($iCount * 13)) $aRichEdit[$iIndex][1] = $iCount EndIf EndFunc ;==>_CheckRichEditLineCountThe second problem could be worked around by having buttons to the side of the edit controls to help select them, but the first is giving me a bit of a headache at present. M23Edit: I have found a solution - now to get it to work elegantly! Edited February 1, 2014 by Melba23 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...
Moderators Melba23 Posted February 2, 2014 Moderators Share Posted February 2, 2014 qwert,That was fun challenge! Here is the final result:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <WinAPI.au3> Global $iEdit_Count = 4 ; Number of edits Global $iEdit_Height = 20 ; Initial height of edits Global $iEdit_Separation = 40 ; Distance from one edit to next Global $iEdit_MaxDrop = 300 ; Max Y coord for expansion Global $iCurrEdit_Index = 0 ; Index number of current edit - 0 = none ; Arrays to hold control data Global $aRichEdit[$iEdit_Count + 1][3] Global $aButton[$iEdit_Count + 1] ; Create GUI $hGUI = GUICreate("Test", 500, 500) ; Create edit controls and focus buttons For $i = 1 To $iEdit_Count $aRichEdit[$i][0] = _GUICtrlRichEdit_Create($hGUI, "", 10, ($i * $iEdit_Separation) - 30, 300, $iEdit_Height, BitOr($ES_MULTILINE, $WS_VSCROLL)) $aRichEdit[$i][1] = 1 ; Lone count - 1 line by default $aRichEdit[$i][2] = Int(($iEdit_MaxDrop - (($i * $iEdit_Separation) - 30) - 7) / ($iEdit_Height - 7)) ; Max lines to expand to reach MaxDrop $aButton[$i] = GUICtrlCreateButton("< " & $i, 320, ($i * $iEdit_Separation) - 30, 30, 20) Next ; Just to have another control $cTest_Button = GUICtrlCreateButton("Test", 10, 300, 80, 30) GUICtrlSetState($cTest_Button, $GUI_FOCUS) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $cTest_Button MsgBox($MB_SYSTEMMODAL, "Hi", "Just for testing") Case Else ; Check if a focus button For $i = 1 To $iEdit_Count If $aButton[$i] = $iMsg Then ; Focus edit _WinAPI_SetFocus($aRichEdit[$i][0]) $iCurrEdit_Index = $i ; Show all edits at original size _ResetAllEdits() ; Reset required depth for edit _CheckRichEditLineCount($i, True) ExitLoop EndIf Next EndSwitch ; Check for curent focus $hCurrFocus = _WinAPI_GetFocus() For $i = 1 To $iEdit_Count ; It is an edit If $aRichEdit[$i][0] = $hCurrFocus Then ; But a new one If $iCurrEdit_Index <> $i Then ; Set focus to new edit $iCurrEdit_Index = $i ; Show all edits at original size _ResetAllEdits() ; Reset required depth for edit _CheckRichEditLineCount($i, True) Else ; Check for changes in edit If _GUICtrlRichEdit_IsModified($aRichEdit[$i][0]) Then ; Set required depth if changes made _CheckRichEditLineCount($i) ; Reset flag _GUICtrlRichEdit_SetModified($aRichEdit[$i][0], False) EndIf EndIf ; No point in looking further ExitLoop EndIf Next ; If no edits focused If $i > $iEdit_Count And $iCurrEdit_Index <> 0 Then ; Show all edits at original size _ResetAllEdits() $iCurrEdit_Index = 0 EndIf WEnd Func _ResetAllEdits() ; Resize and show all edits For $i = 1 To $iEdit_Count WinMove($aRichEdit[$i][0], "", Default, Default, Default, $iEdit_Height) ControlShow($hGUI, "", $aRichEdit[$i][0]) Next EndFunc Func _CheckRichEditLineCount($iIndex, $fReset = False) Local $iEdit_Depth = 0 If $aRichEdit[$iIndex][1] < $aRichEdit[$iIndex][2] Then ; Get line count of current edit Local $iCount = _GUICtrlRichEdit_GetLineCount($aRichEdit[$iIndex][0]) ; If line number has changed or reset is required If $iCount <> $aRichEdit[$iIndex][1] Or $fReset = True Then ; Calulate required size $iEdit_Depth = 7 + ($iCount * ($iEdit_Height - 7)) ; Resize edit WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, $iEdit_Depth) ; Save line count $aRichEdit[$iIndex][1] = $iCount EndIf Else ; Calculate max size $iEdit_Depth = 7 + ($aRichEdit[$iIndex][2] * ($iEdit_Height - 7)) ; Resize edit WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, $iEdit_Depth) EndIf ; How far down does the edit go? Local $iEdit_Bottom = ($iIndex * $iEdit_Separation) - 30 + $iEdit_Depth ; Check lower edits to see if overlapped For $i = $iIndex + 1 To $iEdit_Count If ($i * $iEdit_Separation) - 30 < $iEdit_Bottom Then ; Hide edit if required ControlHide($hGUI, "", $aRichEdit[$i][0]) EndIf Next EndFunc ;==>_CheckRichEditLineCountI am quite pleased with that. Please 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...
qwert Posted February 2, 2014 Author Share Posted February 2, 2014 Melba23, THAT is an outstanding solution. It exceeds what I had hoped for: ►The fields are limited in total length so they are confined to an area of the GUI. ►The fields convert to a scrollable field only when content size is too large per above. ►The fields accept drag/drop text. ►The number of fields is specified by a single parameter. As icing on the cake, I added a button/area of the screen to deselect ... which works great. Here's a screen shot of my result so far. You have made my day. Thanks very much. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 2, 2014 Moderators Share Posted February 2, 2014 qwert,Glad I could help. 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...
qwert Posted February 3, 2014 Author Share Posted February 3, 2014 @Melba23: I do have one additional question. I'm trying to increase the font size to 14. You identified the major parameters from the start: Global $iEdit_Count = 4 ; Number of edits Global $iEdit_Height = 20 ; Initial height of edits Global $iEdit_Separation = 40 ; Distance from one edit to next Global $iEdit_MaxDrop = 300 ; Max Y coord for expansion But in the _CheckRichEditLineCount function you use a constant of 7. I've tried different values to correspond to a font size of 14, but I can't get the sizing to behave. (The size of a field doesn't increase properly as entries are made.) Would you mind pointing out which lines need to change for a font increase from 8.5 to 14? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2014 Moderators Share Posted February 3, 2014 (edited) qwert,As I explained in my first post in the thread, I derived the values to use when expanding the edit controls empirically - better known as "trial and error". If I find the time I will see if I can find a way to determine the correct values programatically later today. M23Edit: A question. You are using RichEdit controls, I presume so various font sizes can be used in each control. If you do use different fonts withint he same control any expansion will fail because there is no easy way of telling the height of each line. Do you really need RichEdit controls or would plain old Edit controls do instead? Edited February 3, 2014 by Melba23 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...
qwert Posted February 3, 2014 Author Share Posted February 3, 2014 Do you really need RichEdit controls or would plain old Edit controls do instead? The fields will have a default font that will serve for all text entry cases. But for certain fields, I'd like to be able to accept rich text from some other source, like text from a browser window. In those few instances, however, it would certainly be acceptable for the default font rules to apply. The field just wouldn't behave quiet as well, but for good reason. Does that help? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2014 Moderators Share Posted February 3, 2014 qwert,I have spent a most frustrating day trying to develop an algorithm to get the edits to expand nicely regardless of the font size. Alas so far I have come up empty handed, so annoyingly I may have to fall back on empirically-derived values for a 14pt font. I will keep at it for a while and let you know if I manage to get anything resolved. 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...
qwert Posted February 3, 2014 Author Share Posted February 3, 2014 I have spent a most frustrating day trying to develop an algorithm Sorry to hear that. Would a simplifying assumption help?: If any non-default text is detected, open the field at its maximum size. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2014 Moderators Share Posted February 3, 2014 qwert,Try this and see what you think:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <WinAPI.au3> Global $iEdit_Count = 4 ; Number of edits Global $iFont_Size = 14 ; Base font size Global $iEdit_Height = $iFont_Size * 2 ; Initial height of edits Global $iEdit_Separation = 40 ; Distance from one edit to next Global $iEdit_MaxDrop = 300 ; Max Y coord for expansion Global $iCurrEdit_Index = 0 ; Index number of current edit - 0 = none ; Arrays to hold control data Global $aRichEdit[$iEdit_Count + 1][4] Global $aButton[$iEdit_Count + 1] ; Create GUI $hGUI = GUICreate("Test", 500, 500) ; Create edit controls and focus buttons For $i = 1 To $iEdit_Count $aRichEdit[$i][0] = _GUICtrlRichEdit_Create($hGUI, "", 10, ($i * $iEdit_Separation) - 30, 300, $iEdit_Height, BitOR($ES_MULTILINE, $WS_VSCROLL)) _GUICtrlRichEdit_SetFont($aRichEdit[$i][0], $iFont_Size) $aRichEdit[$i][1] = 1 ; Lone count - 1 line by default $aRichEdit[$i][2] = $iEdit_MaxDrop - (($i * $iEdit_Separation) - 30) ; Max size for expansion $aButton[$i] = GUICtrlCreateButton("< " & $i, 320, ($i * $iEdit_Separation) - 30, 30, 20) Next ; Just to have another control $cTest_Button = GUICtrlCreateButton("Test", 10, 300, 80, 30) GUICtrlSetState($cTest_Button, $GUI_FOCUS) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $cTest_Button MsgBox($MB_SYSTEMMODAL, "Hi", "Just for testing") Case Else ; Check if a focus button For $i = 1 To $iEdit_Count If $aButton[$i] = $iMsg Then ; Focus edit _WinAPI_SetFocus($aRichEdit[$i][0]) $iCurrEdit_Index = $i ; Show all edits at original size _ResetAllEdits() ; Reset required depth for edit _CheckRichEditLineCount($i, True) ExitLoop EndIf Next EndSwitch ; Check for curent focus $hCurrFocus = _WinAPI_GetFocus() For $i = 1 To $iEdit_Count ; It is an edit If $aRichEdit[$i][0] = $hCurrFocus Then ; But a new one If $iCurrEdit_Index <> $i Then ; Set focus to new edit $iCurrEdit_Index = $i ; Show all edits at original size _ResetAllEdits() ; Reset required depth for edit _CheckRichEditLineCount($i, True) Else ; Check for changes in edit If _GUICtrlRichEdit_IsModified($aRichEdit[$i][0]) Then ; Set required depth if changes made _CheckRichEditLineCount($i) ; Reset flag _GUICtrlRichEdit_SetModified($aRichEdit[$i][0], False) EndIf EndIf ; No point in looking further ExitLoop EndIf Next ; If no edits focused If $i > $iEdit_Count And $iCurrEdit_Index <> 0 Then ; Show all edits at original size _ResetAllEdits() $iCurrEdit_Index = 0 EndIf WEnd Func _ResetAllEdits() ; Resize and show all edits For $i = 1 To $iEdit_Count WinMove($aRichEdit[$i][0], "", Default, Default, Default, $iEdit_Height) ControlShow($hGUI, "", $aRichEdit[$i][0]) Next EndFunc ;==>_ResetAllEdits Func _CheckRichEditLineCount($iIndex, $fReset = False) Local $iEdit_Depth = 0, $iEdit_Bottom Local $aEdit_Font = _GUICtrlRichEdit_GetFont($aRichEdit[$iIndex][0]) ; Check if all same font If $aEdit_Font[0] = 0 Then ; Not all the same size so max edit immediately WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, $aRichEdit[$i][2]) _Check_Visible($iIndex, $aRichEdit[$i][2]) Else ; Get line count of current edit Local $iCount = _GUICtrlRichEdit_GetLineCount($aRichEdit[$iIndex][0]) If $iCount <> $aRichEdit[$iIndex][1] Or $fReset = True Then ; Calulate required size $iEdit_Depth = ($iFont_Size * 2) + (($iFont_Size * 2) - 2) * ($iCount - 1) If $iEdit_Depth > $aRichEdit[$i][2] Then If Not $aRichEdit[$iIndex][3] Then $aRichEdit[$iIndex][3] = ($iFont_Size * 2) + (($iFont_Size * 2) - 2) * ($iCount - 2) EndIf $iEdit_Depth = $aRichEdit[$iIndex][3] EndIf ; Resize edit WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, $iEdit_Depth) ; Save line count $aRichEdit[$iIndex][1] = $iCount _Check_Visible($iIndex, $iEdit_Depth) EndIf EndIf EndFunc ;==>_CheckRichEditLineCount Func _Check_Visible($iIndex, $iEdit_Depth) ; How far down does the edit go? $iEdit_Bottom = ($iIndex * $iEdit_Separation) - 30 + $iEdit_Depth ; How far down does the edit go? $iEdit_Bottom = ($iIndex * $iEdit_Separation) - 30 + $iEdit_Depth ; Check lower edits to see if overlapped For $i = $iIndex + 1 To $iEdit_Count If ($i * $iEdit_Separation) - 30 < $iEdit_Bottom Then ; Hide edit if required ControlHide($hGUI, "", $aRichEdit[$i][0]) Else ControlShow($hGUI, "", $aRichEdit[$i][0]) EndIf Next EndFunc ;==>_Check_VisibleI have used your assumption for when non-standard font sizes are detected. 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...
qwert Posted February 3, 2014 Author Share Posted February 3, 2014 I think it's a very workable solution. The only hitch is that typing an entry now has a strange effect on the initial line or two. It tries to shift gears between a having a vertical scroll bar or not. For three lines and more, it works just like before. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2014 Moderators Share Posted February 3, 2014 qwert,I have slightly modified the sizing code - for me this is pretty good: Func _CheckRichEditLineCount($iIndex, $fReset = False) Local $iEdit_Depth = 0, $iEdit_Bottom ; Get current style Local $iCurr_Style = _WinAPI_GetWindowLong($aRichEdit[$iIndex][0], $GWL_STYLE) Local $aEdit_Font = _GUICtrlRichEdit_GetFont($aRichEdit[$iIndex][0]) ; Check if all same font If $aEdit_Font[0] = 0 Then ; Not all the same size so max edit immediately WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, $aRichEdit[$i][2]) _Check_Visible($iIndex, $aRichEdit[$i][2]) Else ; Get line count of current edit Local $iCount = _GUICtrlRichEdit_GetLineCount($aRichEdit[$iIndex][0]) If $iCount <> $aRichEdit[$iIndex][1] Or $fReset = True Then ; Calulate required size $iEdit_Depth = (($iFont_Size * 2) + 1) + (($iFont_Size * 2) - 2) * ($iCount - 1) If $iEdit_Depth > $aRichEdit[$i][2] Then If Not $aRichEdit[$iIndex][3] Then $aRichEdit[$iIndex][3] = (($iFont_Size * 2) + 1) + (($iFont_Size * 2) - 2) * ($iCount - 2) EndIf $iEdit_Depth = $aRichEdit[$iIndex][3] EndIf ; Resize edit WinMove($aRichEdit[$iIndex][0], "", Default, Default, Default, $iEdit_Depth) ; Save line count $aRichEdit[$iIndex][1] = $iCount _Check_Visible($iIndex, $iEdit_Depth) EndIf EndIf EndFunc ;==>_CheckRichEditLineCountThere is still a flash of scrollbar but that is to be expected as the resizing takes a short time to be applied and until then the edit thinks it needs a scroll bar. And I think that is it as far as I am concerned. Good luck with the rest of the project. 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...
qwert Posted February 3, 2014 Author Share Posted February 3, 2014 Thank you for making the extra effort. This result will be very useful. My goal now is to understand these things to the point that they become familiar tools in my own working set. Your use of an array for the field defs, for example, opens up a new dimension of possibilities (pun not intended). It's not something I normally think to do, so it's another learning experience. I really appreciate what you've provided. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2014 Moderators Share Posted February 4, 2014 qwert,Glad I could help. Please do ask if you have any questions about how or why I did something particular. 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...
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