Jump to content

How do I remove the Horizontal Scroll Bar from an Edit Control

Recommended Posts

My code.

Does not work

;~ [optional] Control styles:
;~     $ES_AUTOHSCROLL - Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line.
;~     $ES_AUTOVSCROLL - Automatically scrolls text up one page when the user presses the ENTER key on the last line.

    Local $hEditNewText = _GUICtrlEdit_Create($hGUI, "This is a test" & @CRLF & "Another Line", 8, 500, 715, 100)
    Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_STYLE) ; get style
    Local $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_EXSTYLE) ; get extended style
    ;GUICtrlSetStyle($hEditNewText, BitXOR($iStyle, $ES_AUTOHSCROLL)) ; remove hscroll left to right (force wrap)
    GUICtrlSetStyle($hEditNewText, BitAND($iStyle, BitNOT($ES_AUTOHSCROLL)))


Also tried this

;~ https://www.autoitscript.com/forum/topic/113598-solved-scrolling-read-only-text-display-using-edit-not-input-control/
    Local $hEditNewText = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 8, 500, 715, 100)
    Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_STYLE) ; get style
    Local $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_EXSTYLE) ; get extended style
    GUICtrlSetStyle($hEditNewText, BitAND($iStyle, BitNOT($ES_AUTOHSCROLL)))


However, this works:

Local $hEditNewText = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 8, 500, 715, 100, $ES_WANTRETURN + $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_MULTILINE + $WS_TABSTOP)

My question stands. How to change the STYLE of an EDIT control?


Edited by Skysnake


Why is the snake in the sky?

Link to post
Share on other sites
  • Moderators


You need to remove the $WS_HSCROLL style from the control styles - the $ES_AUTOHSCROLL merely allows the control to automatically scroll as you type. This is why the final snippet works and the others do not, as you only remove the correct style in that final one - in the first 2 the edit control is created with the $WS_HSCROLL as a default style as explained in the Help file.

This works for me:

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

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

; Create edit without the $WS_HSCROLL style
$cEdit = GUICtrlCreateEdit("", 10, 10, 200, 200, Bitor($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE


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:


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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By User71
      Hi All,
      I'm sure this is a simple one to answer and I have searched and experimented before I asked (well enough hopefully!)
      I'm trying to set a button background to be white, the font colour red, centred vertically and horizontally and multi-line. Can it be done?
      Here is my example code:
      #include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #include <FontConstants.au3> #include "ColorConstants.au3" Opt("GUIOnEventMode", 1) $GUI = GUICreate("GUI", 250, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Button = GUICtrlCreateButton("Button" & @CRLF & "One", 160, 185, 85, 110, BitOR($BS_MULTILINE, $BS_CENTER, $BS_VCENTER, $WS_EX_WINDOWEDGE)) GUICtrlSetBkColor(-1, $COLOR_White) GUICtrlSetFont($Button, 14, 800, 0, "MV Boli", 5) GUICtrlSetColor($Button, 0xFF0000) GUICtrlSetOnEvent($Button, "_Exit") GUISetState() While 1 Sleep(100) WEnd Func _Exit() Exit EndFunc ;==>_ExitWith everything I have tried, this is the closest I get, button white, font red, correct font, but no centring and sometimes no multi-line (depending on button text and font size). I saw I might have to add the default button forced style back in so I did that too $WS_EX_WindowEdge.
      Thanks for any help and apologies if I've missed an obvious answer to this elsewhere.
  • Create New...