Edit control: right-aligned control but left-aligned text
Posted: 22 Oct 2017, 21:04
In this example, the text of Notepad's Edit control is set, and the control is set to right-aligned text. Short lines appear right-aligned as expected, but any lines longer than the visible part of the control appear as though they are left-aligned. Does anyone know of any workaround for this? Cheers.
I was checking through various lines of code, and I wanted to inspect the ends of the lines only. A workaround is to pad each line with spaces.
Code: Select all
q:: ;Notepad - Edit control align right
vText := "
(Join`r`n
abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
)"
ControlGetText, vText2, Edit1, ahk_class Notepad
if (vText2 = "")
{
;ES_RIGHT := 0x2
Control, Style, +0x2, Edit1, ahk_class Notepad
ControlSetText, Edit1, % vText, ahk_class Notepad
}
return
Code: Select all
w:: ;pad text with leading spaces (assumes an equal-width font e.g. Courier New)
vText := "
(Join`r`n
abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz abcdefghijklm nopqrstuvwxyz
)"
vLen := 0
Loop, Parse, vText, `n, `r
if (StrLen(A_LoopField) > vLen)
vLen := StrLen(A_LoopField)
vWhitespace := ""
Loop, % vLen
vWhitespace .= " "
vOutput := ""
Loop, Parse, vText, `n, `r
vOutput .= (A_Index=1?"":"`r`n") SubStr(vWhitespace, 1, vLen-StrLen(A_LoopField)) A_LoopField
ControlGetText, vText2, Edit1, ahk_class Notepad
if (vText2 = "")
ControlSetText, Edit1, % vOutput, ahk_class Notepad
return