Jump to content

RichEdit @TAB - how to set to 8 characters width?


orbs
 Share

Recommended Posts

in Edit control, @TAB sends the caret to nearest multiple of 8 characters width. this is regardless of font size etc.

in RichEdit control, settings for @TAB is very confusing and messy. it does not depend on character width, but on other units of measures, such as cm,mm,pt and such. so i can't seem to find a way to set it the same way as in Edit control. i'm using monospace font, if that's of any use.

google offers no help, as any searches for "TAB" return results for a Tab control... :'(

any ideas?

i'm thinking of wrapping _GUICtrlRichEdit_AppendText() to replace @TAB with a computed amount of whitespaces that would match nearest 8-characters-width multiple... but there has to be a better way, i hope.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Read about:
 

_GUICtrlRichEdit_SetParaTabStops()

and
https://msdn.microsoft.com/pl-pl/library/windows/desktop/bb761663(v=vs.85).aspx

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

you probably mean:

_GUICtrlRichEdit_SetTabStops()

rather than:

_GUICtrlRichEdit_SetParaTabStops()

anyway i tried them both, did not see a way to set @TAB width depending on the width of a character.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Post here an exmaple what you have tried.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

comments inside:

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

Global $hGUI = GUICreate('RichEdit @TAB width test', 320, 320, -1, -1)
GUISetBkColor(0xFEDCBA)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, '', 10, 10, 300, 300, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetFont($hRichEdit, 9, 'Courier New')

_GUICtrlRichEdit_SetTabStops($hRichEdit, 0.6)
; 0.6 is the nearest guess to 8-characters-width of Courier New at size 9.
; it's not exact, and will stop working if i set different font size.
_GUICtrlRichEdit_AppendText($hRichEdit, '1234567' & @TAB & '1234567' & @TAB & '1234567')

GUISetState(@SW_SHOW)
While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

_GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
GUIDelete()

 

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Try this:

;~ https://www.autoitscript.com/forum/topic/185490-richedit-tab-how-to-set-to-8-characters-width/

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

Global $hGUI = GUICreate('RichEdit @TAB width test', 320, 320, -1, -1)
GUISetBkColor(0xFEDCBA)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, '', 10, 10, 300, 300, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUISetState(@SW_SHOW)

_GUICtrlRichEdit_SetFont($hRichEdit, 9, 'Courier New')

_GUICtrlRichEdit_SetSpaceUnit("pt")

; 0.6 is the nearest guess to 8-characters-width of Courier New at size 9.
; it's not exact, and will stop working if i set different font size.
_GUICtrlRichEdit_AppendText($hRichEdit, '1234567' & @TAB & '1234567' & @TAB & '1234567' & @CRLF)

MsgBox(0, '', 1)
_GUICtrlRichEdit_SetFont($hRichEdit, 12, 'Courier New')
_GUICtrlRichEdit_AppendText($hRichEdit, 'B234567' & @TAB & 'B234567' & @TAB & '1234567' & @CRLF)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

_GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
GUIDelete()

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Your original script actually works. The TabStops works per inch, every X inch of the edit control is where the tab can fit, if there's 7 characters in that inch and then you add tab, the tab is only going to use the last 1 character position for its tab.

This isn't going to be exact because the TabStop function works in inches, which doesn't get as precise as millimeters or pixels (pixels would be ideal since that's what everything is measured in... but I'm guessing this is an outdated function, I don't really know)

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <String.au3>

Global $hGUI = GUICreate('RichEdit @TAB width test', 420, 320, -1, -1)
GUISetBkColor(0xFEDCBA)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, '', 10, 10, 400, 300, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetFont($hRichEdit, 9, 'Courier New')
Global $iCharPerTab = 8
Global $sMeausre = ""

For $i = 1 to $iCharPerTab
    $sMeausre &= $i
Next

_GUICtrlRichEdit_SetTabWidth($hRichEdit, $iCharPerTab)
_GUICtrlRichEdit_AppendText($hRichEdit, $sMeausre & @CRLF & _StringRepeat(" ", $iCharPerTab) & @CRLF & @TAB & @CRLF & $sMeausre)

GUISetState(@SW_SHOW)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

_GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
GUIDelete()

; Sets the tab width based on how many characters wide you want it to be
Func _GUICtrlRichEdit_SetTabWidth(Const $hRichControl, Const $iWidth)
    Local $aDimensions = GUIMeasureString(" ", $hRichControl)
    If (Not @Error) Then Return _GUICtrlRichEdit_SetTabStops($hRichEdit, PixelToInch($aDimensions[0] * ($iWidth - 1)))
    Return SetError(1, 0, 0)
EndFunc

; Convert the pixels of how wide the tab character is to inches, which is what the TabStops function uses
Func PixelToInch(Const $iPixel)
    Local Static $iDpi = GetSystemDpi()
    ConsoleWrite(Round(($iPixel / $iDpi) * 2, 1) & @LF)
    Return Round(($iPixel / $iDpi) * 2, 1)
EndFunc

; Get the DPI of the system, this will be used to calculate how wide the tab character will be based on the system dpi
Func GetSystemDpi()
   Local $hDC = _WinAPI_GetDC(0)
   Local $iDeviceCaps = _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSX)
   _WinAPI_ReleaseDC(0, $hDC)
   Return $iDeviceCaps
EndFunc

; Measure a string, used to get the width of the space character
Func GUIMeasureString(Const $vString, $iCtrlid = Default, Const $iSize = Default, Const $iWeight = Default, Const $iAttribute = Default, Const $sFontName = Default, Const $iQualiy = Default)
    Local $bCreatedId = False

    If ($vString = "") Then Return SetError(1, 0, $vString)

    If ($iCtrlid = Default) Then
        $bCreatedId = True
        $iCtrlid = GUICtrlCreateLabel("", -100, 0, 1, 1)
        GUICtrlSetFont($iCtrlid, $iSize, $iWeight, $iAttribute, $sFontName, $iQualiy)
    EndIf

    Local $hWnd = (IsHWnd($iCtrlid) ? $iCtrlid : GUICtrlGetHandle($iCtrlid))
    Local $iStringLen = StringLen($vString)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT)
    Local $hSelectObject = _WinAPI_SelectObject($hDC, $hFont)
    Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, $vString)
    Local $aReturn[2] = [DllStructGetData($tSize, 1), DllStructGetData($tSize,2)]
    $tSize = Null

    _WinAPI_SelectObject($hDC, $hSelectObject)
    _WinAPI_ReleaseDC($hWnd, $hDC)

    If ($bCreatedId) Then GUICtrlDelete($iCtrlid)

    Return $aReturn
EndFunc   ;==>LongStringToArray

You could also just replace the tab character with 8 spaces yourself, whenever the tab key is pressed

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WinAPI.au3>
#include <WinAPIShellEx.au3>
#include <WindowsConstants.au3>

Global $hGUI = GUICreate('RichEdit @TAB width test', 420, 320, -1, -1)
GUISetBkColor(0xFEDCBA)
Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, '', 10, 10, 400, 300, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetFont($hRichEdit, 9, 'Courier New')
Global $iCharPerTab = 8
Global $sTab = ""

Global $hNewWindowProc = DllCallbackRegister("NewWindowProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")
Global $pNewWindowProc = DllCallbackGetPtr($hNewWindowProc)

For $i = 1 to $iCharPerTab
    $sTab &= ' '
Next

_GUICtrlRichEdit_AppendText($hRichEdit, 12345)

GUISetState(@SW_SHOW)
_WinAPI_SetWindowSubclass($hRichEdit, $pNewWindowProc, 9999)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

_WinAPI_RemoveWindowSubclass($hRichEdit, $pNewWindowProc, 9999)
_GUICtrlRichEdit_Destroy($hRichEdit)
GUIDelete()

Func NewWindowProc($hWnd, $iMsg, $wParam, $lParam, $uIdSubclass, $dwRefData)
    #forceref $hWnd, $iMsg, $wParam, $lParam, $uIdSubclass, $dwRefData

    Switch ($iMsg)
        Case $WM_CHAR
            If ($wParam = 9) Then Return _GUICtrlRichEdit_InsertText($hRichEdit, $sTab)
    EndSwitch

    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>KeyProc

 

Link to comment
Share on other sites

@mLipok, i don't see any difference between your example and the default behaviour of the RichEdit... the tab stops at same distance, regardless of font size. what are you trying to demonstrate?

 

@InunoTaishou

On 11/11/2016 at 7:02 PM, InunoTaishou said:

Your original script actually works ... This isn't going to be exact because the TabStop function works in inches

yes i know that, and that is exactly my problem.

On 11/11/2016 at 7:02 PM, InunoTaishou said:

You could also just replace the tab character with 8 spaces yourself, whenever the tab key is pressed

this i already mentioned as a possible solution, but it's not a constant 8 spaces, it has to be computed to the nearest 8-characters-multiple - i'd have to count how many characters exist from beginning of line until caret. and it will not be correct for long - if i add a character in there, then that calculation becomes invalid.

 

i really have no clue as to how to proceed.

 

EDIT: here's a better demo of the issue: i added a ComboBox by which you can change the font size and see how the spacing between TAB-separated substrings change:

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

Global $hGUI = GUICreate('RichEdit @TAB width test', 520, 340, -1, -1)
GUISetBkColor(0xFEDCBA)

GUICtrlCreateLabel('Font Size:', 415, 9)
Global $gComboFontSize = GUICtrlCreateCombo('', 470, 5, 40, 20, $CBS_DROPDOWNLIST)
For $i = 6 To 14
    GUICtrlSetData($gComboFontSize, $i)
Next
Global $iFontSize = 9
GUICtrlSetData($gComboFontSize, $iFontSize)

Global $hRichEdit = _GUICtrlRichEdit_Create($hGUI, '', 10, 30, 500, 300, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
_GUICtrlRichEdit_SetFont($hRichEdit, $iFontSize, 'Courier New')

_GUICtrlRichEdit_SetTabStops($hRichEdit, 0.6)
; 0.6 is the nearest guess to 8-characters-width of Courier New at size 9.
; it's not exact, and will stop working if i set different font size.
_GUICtrlRichEdit_AppendText($hRichEdit, _
        '1234567' & @TAB & '1234567' & @TAB & '1234567' & @CRLF & _
        '12345678' & @TAB & '1234' & @TAB & '12' & @CRLF)
GUISetState(@SW_SHOW)
While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $gComboFontSize
            $iFontSize = GUICtrlRead($gComboFontSize)
            _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1)
            _GUICtrlRichEdit_SetFont($hRichEdit, $iFontSize, 'Courier New')
            _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True)
    EndSwitch
WEnd

_GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
GUIDelete()

 

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

14 hours ago, orbs said:

i don't see any difference between your example and the default behaviour of the RichEdit... the tab stops at same distance, regardless of font size. what are you trying to demonstrate?

I misunderstood you.
Sorry.

On 11.11.2016 at 10:40 AM, orbs said:

google offers no help, as any searches for "TAB" return results for a Tab control.

Did you read this following pages:

http://stackoverflow.com/questions/154204/modifying-default-tab-size-in-richtextbox

https://www.experts-exchange.com/questions/10069878/Richedit-TabStops.html

https://www.experts-exchange.com/questions/20326576/RichEdit-Run-Time-Formatting.html

 

?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

ok, so after some thought, i made it to the conclusion that i'm thinking about it all wrong.

RichEdit is not an "enhanced" Edit control. i.e. it does not support all features of Edit, and adding upon it. rather, it is built from scratch with the notion that multiple objects should coexist comfortably (fonts, sizes, colors, images, etc.). so in that sense, it makes a lot of sense to define tab stops in absolute length, rather than related to character width.

i withdraw my attempts to use character width as a tab stop. for my specific needs, i wanted a RichEdit to support color highlight. fortunately, i can forfeit that. so i will revert the code to use "poor" Edit control.

sorry for sending you on a wild goose chase.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

8 hours ago, orbs said:

RichEdit is not an "enhanced" Edit control

RichEdit is rather full editor like WORD , TxTextControl, PDF (in some sense).

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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