Jump to content

Auto resize contol on GUI resize

Recommended Posts


I think I am missing something obvious

I want the "color bar" to stretch from side to side (entire width) of the GUI.  On resize it must expand / contract as necessary.  I guess the answer is easy, but I need a bit of help please?

$hForm = GUICreate('myColor Picker', 300, 200,-1, -1, $WS_MAXIMIZEBOX + $WS_SYSMENU + $WS_CAPTION)
;color the GUI background

;GUISetBkColor($sColorformFile, $hForm) ; set the gui background color

;Local $mycolorLabel = GUICtrlCreateLabel("",10,10,300,10) ; a blank LABEL color bar
Local $mycolorLabel = GUICtrlCreateGraphic( -1,-1,300,10) ; a blank GRAPHIC color bar
GUICtrlSetResizing($mycolorLabel, $ws_sizebox);$GUI_DOCKMENUBAR);$GUI_DOCKAUTO) ;$GUI_DOCKBORDERS)
GUICtrlSetBkColor($mycolorLabel,$sColorformFile) ; set the color for the label


This is an extract from here, by @Yashied

$hForm = GUICreate('myColor Picker', 300, 200,-1, -1, $WS_MAXIMIZEBOX + $WS_SYSMENU + $WS_CAPTION)
;color the GUI background

;GUISetBkColor($sColorformFile, $hForm) ; set the gui background color

;Local $mycolorLabel = GUICtrlCreateLabel("",10,10,300,10) ; a blank LABEL color bar
Local $mycolorLabel = GUICtrlCreateGraphic( -1,-1,300,10) ; a blank GRAPHIC color bar
GUICtrlSetResizing($mycolorLabel, $ws_sizebox);$GUI_DOCKMENUBAR);$GUI_DOCKAUTO) ;$GUI_DOCKBORDERS)
GUICtrlSetBkColor($mycolorLabel,$sColorformFile) ; set the color for the label

Specifically my issue is with that $mycolorLabel

Thanks, Skysnake



Why is the snake in the sky?

Share this post

Link to post
Share on other sites


From the Help file for GUICtrlCreateGraphic:


This control cannot be resized due to fix graphic relative addressing creation but can be dock with GUICtrlSetResizing().

So you cannot change the size of the control when  resizing the GUI, only the position of the control within the resized GUI.


  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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


Share this post

Link to post
Share on other sites

lots of code :(

Thanks @Melba23



Why is the snake in the sky?

Share this post

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

  • Similar Content

    • Tjalve
      By Tjalve
      Hello fellow coders.
      Im currently making a GUI for a webapp. Im using a REST API to get information and display this in a Tree view. Its basically a scheduler of "tasks" and these tasks are great to display in a tree view.
      The problem im having is that on some servers the tree can get rather large. So my GUI is reziable in ordet to be able to fit all the tasks in the view. I have then used GUICtrlSetResizing with diffrent options to get the GUI to look alright even when i resize it. It works fine an all GUI elements, except for the Tree-view. And if i remember correctly, the treeview item is another type of object and you cannot use regular GUI functions on it. Therefor im wondering of there are any alternatives?
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 208, 220, 192, 124,$WS_SIZEBOX) $idTV = _GUICtrlTreeView_Create($Form1, 4, 25, 200, 140) GUICtrlSetResizing(-1,$GUI_DOCKMENUBAR) $Button1 = GUICtrlCreateButton("Button1", 8, 168, 75, 25) GUICtrlSetResizing(-1,$GUI_DOCKSTATEBAR) $Text = GUICtrlCreateLabel("Text", 8, 8, 25, 17) GUICtrlSetResizing(-1,$GUI_DOCKMENUBAR) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd This code is an example of my problem (run it and try to resize the window). If anyone has any ideas i would appreciate it  
    • GregEisenberg
      By GregEisenberg
      Hi there 
      I am building a "statistics kiosk" where we will be enumerating through Web Pages, and Excel files, PDF reports and other applications each displaying statistics relevant to our project. I want to overlay some context over each page/screen so that viewers of this "statistics kiosk" have some info about that the data they are looking at is.  I have written a function called OverlayWindow which is supposed to create a transparent window which displays some text. The function SEEMS to work BUT 
      The handle returned from CreateGUI is 0 (despite there being NO error or extended information)  The window is created but not maintained.  In other words it appears but since it is not really maintained it is repainted as other content changes.  The result is that the overlay appears BUT as soon as there is a reason for the underlying windows to repaint the overlay starts to "disappear"  I have extracted the relevant code and created the most simplistic of samples here. 
      #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPISysWin.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode ; #FUNCTION# ==================================================================================================================== ; Name ..........: OverlayWindow ; Description ...: Throws up a child window with transparent background over current window ; ; Parameters : ; $hwndParent parent hwnd ; $rectToHighlight rect to draw (or if null, skip) ; $rectForText rect for textToWrite ; $textToWrite the text to write ; =============================================================================================================================== Func OverlayWindow($hwndParent, $rectToHighlight, $rectForText, $textToWrite) $style = BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS) $exstyle = BitOR($WS_EX_TOPMOST, $WS_EX_COMPOSITED, $WS_EX_TRANSPARENT) $hGUI = GUICreate("transparent overlay", -1, -1, -1, -1, $style, $exstyle) ConsoleWrite("**** $hGUI: " & $hGUI & @CRLF) ConsoleWrite("**** @error: " & @error & @CRLF) ConsoleWrite("**** @extended: " & @extended & @CRLF) GUISetOnEvent($GUI_EVENT_CLOSE, "OverlayWindow_Exit") GUISetState(@SW_SHOW, $hGUI) $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ConsoleWrite("**** $hGraphics : " & $hGraphics & @CRLF) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 4) ; Red If ($rectToHighlight <> Null) Then _GDIPlus_GraphicsDrawRect($hGraphics, $rectToHighlight[0], $rectToHighlight[1], $rectToHighlight[2], $rectToHighlight[3], $hPen) EndIf _GDIPlus_PenDispose($hPen) $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000) ; RED $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 14, 2) $tLayout = _GDIPlus_RectFCreate($rectForText[0], $rectForText[1], $rectForText[2], $rectForText[3]) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $textToWrite, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphics, $textToWrite, $hFont, $aInfo[0], $hFormat, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_FontDispose($hFont) _GDIPlus_GraphicsDispose($hGraphics) Return $hGUI EndFunc Func OverlayWindow_Exit() ConsoleWrite("* * * Exit event called" & @CRLF) EndFunc Func Handle_Esc() $Done = True EndFunc ;----------------------------------------------------------------- ;Main() _GDIPlus_Startup() Global $Done = False Local $rect = [10, 10, 400, 400] Local $rectForText = [15, 15, 380, 380] $hGUI = OverlayWindow(Null, $rect, $rectForText, "This is a test with long text long text and should automatically wrap long text " & @CRLF & "and " & @CRLF & " handle " & @CRLF & "cariage returns and line feeds") HotKeySet ( "{Esc}", Handle_Esc) While Not $Done Sleep(100) WEnd GUIDelete($hGUI) _GDIPlus_Shutdown () Exit 0 I am assuming the since CreateGUI returns 0 that the  _GDIPlus_GraphicsCreateFromHWND is simply creating a "graphics context" based on the desktop then and not on my window.  And thus - there IS no window (despite no @error nor no @extended data) 
      So I think the issue is in the "styles" of window I am using.
      If I don't use WS_CHILD (for example I use WS_POPUP) then I get a handle back for my window and the lifetime of the window is what i want but it is not transparent as I want. Setting styles on the window to be transparent (either using extended styles, or using WinSetTrans or _WinAPI_SetBkMode) results in my rectangle and string being transparent - not what I want either. 

      Any suggestions?

      any and all help is appreciated


    • Miliardsto
      By Miliardsto
      Hello I have problem with my object drawn in gdi
      Func drawTriangle($tabName,$gui_active = 0) _GDIPlus_Startup() ;initialize GDI+ Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($sGUI[$gui_active]) ;create a graphics object from a window handle _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFEFEFEF) ;color format AARRGGBB (hex) Local $aPoints[5][3] $aPoints[0][0] = 4 $aPoints[1][0] = 0.0 ; left $aPoints[1][1] = 0.0 ; top $aPoints[2][0] = 0.0 ; left $aPoints[2][1] = 30.0 ; top $aPoints[3][0] = 80.0 ; left $aPoints[3][1] = 30.0 ; top $aPoints[4][0] = 110.0 ; left $aPoints[4][1] = 0.0 ; top _GDIPlus_GraphicsFillPolygon($hGraphics, $aPoints, $hBrush) ;draw the triangle Local $fBrush = _GDIPlus_BrushCreateSolid(0xFFAAAAAA) ;color format AARRGGBB (hex) Local $sString = $tabName, $aInfo ; from the func param Local $hFormat, $hFamily, $hFont, $tLayout $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI") $hFont = _GDIPlus_FontCreate($hFamily, 12, 2) $tLayout = _GDIPlus_RectFCreate(6, 2) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString, $hFont, $aInfo[0], $hFormat, $fBrush) ;_GDIPlus_GraphicsDrawString($hGraphics, $tabName, 6, 3, "Segoe UI", 12) ; write text ;cleanup GDI+ resources _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_Shutdown() EndFunc After this code execution I got new object rectangle
      Global $ma_border = GUICtrlCreateGraphic(100, 180, 40, 40) GUICtrlSetGraphic($ma_border, $GUI_GR_COLOR, 0x00000, $COLOR_BLUE) GUICtrlSetGraphic($ma_border, $GUI_GR_RECT, 0, 0, 40, 40) GUICtrlSetState(-1,$GUI_DISABLE) And what happens is first func = draw rectangle is pushed to parameters from GUICtrlCreateGraphic func. Left: 100, Top: 180.
      I can simplu reverse order of these func execution but There is too much things to change in my code.
      Can something be done to prevent this slipping?
    • DynamicRookie
      By DynamicRookie
      I am developing a script that types a  string that can be specified in the Inputbox that has the $In01 variable attached.
      But 3 things are not working:
      It's not loading the gui, even when Guicreate() is specified in the code It's not typing the string, and i dont know why it doesn't type it. And last of them, It's not detecting if the script has a different name than the original, My Script is below:
      ;Script STRNG= 103494x104955x01 #include <Misc.au3> #Include <File.au3> #include <GuiConstants.au3> #INCLUDE <GuiConstantsEx.au3> #pragma compile(inputboxres, true)" If @ScriptName Not = "DynamicRookie's Colorized No. 103494x104955x01.au3" Then MsgBox(0, "Unofficial", "You are running an unnoficial version of STRNG: 103494x104955x01 by DynamicRookie, but feel free to use it below your own risk :)") ShellExecute("https://www.autoitscript.com/forum/profile/104955-dynamicrookie/") EndIf $StringVal116 = 1 $Const_Win32_idGetHandle = WinGetHandle("103494x104955x01", "1x1") Sleep (10) Hotkeyset("{=}", "_ResetVariable") SetError(0, 0, 0) $In01 = InputBox("In01", "Please enter the string you want to automate :)") If @error = 4 Then Call("ConsoleErrorFunction") EndIf MsgBox(4, "In03", "Want to enable _HasToRenewVal Function? (DEFAULT: Yes)") If $IDYES = 6 Then $_HTRVal = True Elseif $IDNO = 7 Then $_HTRVal = False EndIf Global $StringVal104910 = 0 ;Default String 0x0x1 :) Global $StringVal116 = 0 ;Custom String 0x5x1 :) Global $State = 1 Global $vReStr = '000' MsgBox(0, "DynaRookie", "Script made by DynamicRookie, for 103494 in AutoIt Forums") GUICreate("103494x104955x01", 400, 400, -1, -1, -1, -1) GUICtrlCreateLabel("103494x104955x01 Active Process", 10, 10, 100, 20, -1, -1) GUICtrlCreateLabel("Value Extension Macrostring: ", 10, 40, 100, 20) $vReStr = GUICtrlCreateLabel("N/V/R", 112, 40, 50, 20) GUICtrlCreateLabel("String Specified: # " & $In01 & " #, type K to type specified string.", 0, 100, 300, 20) Call("_D4N4M11CCKR010K133") ;It waits until u press K to check for $In03 and if checked to type type $In01 in the chat, then you need to press "=" key to enable the variable back, else ;If HasToRenew function is enabled you dont need to enable it back, ;else if the variable is already enabled and you dont want to make it type $In01 when you press K, press "=" when ;the variable is already enabled, it will deactivate it until you press "=" again. Func Init0() GUICtrlSetData($vReStr, 'Initializing: Control 0x1') $StatusString = "Init0" Sleep(1) $i_Win32_idPosition = WinGetPos("103494x104955x01", "1x2") $i_Win32_Status = "Active0" GUICtrlSetData($vReStr, 'Ready to use!') $StatusString = "RD1" Call("_D4N4M11CCKR010K133") EndFunc Func _D4N4M11CCKR010K133() While 1 If _IsPressed('4B') And $StringVal116 = 1 Then $StringVal104910 = 1 ExecuteFunction_0_0_0_1() EndIf Sleep(100) WEnd EndFunc Func _ResetVariable() If $State = 0 And $_HTRVal = True Then $State = 1 Call ("_D4N4M11CCKR010K133") Elseif $State = 1 And $_HTRVal = True Then $State = 0 Call ("_D4N4M11CCKR010K133") Else Call("_D4N4M11CCKR010K133") EndIf Endfunc Func ExecuteFunction_0_0_0_1() If $StatusString = "Init0" Then MsgBox(0, "Wait", "Please wait until it loads completely") Call("Init0") ElseIf $State = 1 And $_HTRVal = True Then GUICtrlSetData($vReStr, "Typing specified string") Send('' & $In01 & '', 1) $State = 0 GuiCtrlSetData($vReStr, "Sent function command!") Call("_D4N4M11CCKR010K133") ElseIf $State = 0 or $State = 1 And _HTRVal = False Then GUICtrlSetData($vReStr, "Typing specified string") Send('' & $In01 & '', 1) GuiCtrlSetData($vReStr, "Sent function command!") Call("_D4N4M11CCKR010K133") Else Call("_D4N4M11CCKR010K133") EndIf EndFunc Func ConsoleErrorFunction() ConsoleWrite($Const_Win32_idGetHandle) MsgBox("1, 48, 256, 4096, 2097152", "Exception @error", "An Unexpected error has occurred, please contact DynamicRookie for help, in AutoIt forums ( This window will close in " & $i_idTimeout_msg & "seconds", $i_idTimeout_msg) Exit 0 If @error = 1 Then ConsoleWrite("User has decided: Cancel = Val. 2") Exit 0 ElseIf @error = 2 Then ShellExecute("https://www.autoitscript.com/forum/profile/104955-dynamicrookie/") ConsoleWrite("User has decided: Nothing = Val. 0") Exit 0 EndIf  
    • Skysnake
      By Skysnake
      Maybe I am just being silly, but I don't understand what is supposed to happen here.
      GuiCreate from the Help file has 2 examples.  Specifically, the 2nd example creates a ChildGui.  Or so it says.  I do not see this on screen.
      $hGUI gets created, no problem.
      Local $hChild = GUICreate("ChildGui", 10, 10, 20, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI) What exactly does this line do? Should I see it on screen?