Jump to content

[SOLVED] Radio Button long text


Recommended Posts

Hello everyones reading this post,

I'm struggling at resizing properly my radio buttons to fit long text inside without affecting others radio buttons and also adjust position of them relative to the string.

I tried with _StringSize UDF but I guess im too tired to figure out how to use it correctly..

I also tried: _Control_SetWidth2Text I found on this forum, it work aslong im not maximizing GUI (radio text is gone when I maximize and maximize is a must)

 

here is the code example, I hope someone can figure out (sorry if guictrlsetpos is not included in the example, I know thats probably the way to go but I wanted to make sure there is nothing better before use it)

Thank you

 

Br,

~WilliamasKumeliukas

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <EditConstants.au3>
#include <GUIListBox.au3>
#include <ButtonConstants.au3>
#include <ProgressConstants.au3>
#include <ColorConstants.au3>
#include <AutoitConstants.au3>
#include <Misc.au3>
#include <WinAPIReg.au3>
#include <WinAPI.au3>


#Region Opt's
Opt("GUIResizeMode", 802)
#EndRegion Opt's



Global $q = "INTRO LINE" & @CRLF & @CRLF & "description of everything until user press start."
Global $file = @TempDir & "\test.p"
destroy()

Global $msg, $score = 0, $rate, $com, $total = 0, $cfile, $cq, $i = 0, $time = 0, $min = 0, $sec = 0, $hour = 0, $qf, $ii = 0


Main()
Func Main()
    Global $iGUIInitSize = 550
    #Region GUI
  Opt("GUICloseOnEsc", 1)
    Global $gui = GUICreate("example", 1124, 550,-1 ,-1, BitOR($WS_MAXIMIZEBOX , $WS_MINIMIZEBOX))
  Global $gui_size = WinGetClientSize($gui)
    Global $iFontSize = Int(2 * (.25 + (8 * $gui_size[0] / $iGUIInitSize))) / 2
    Global $options = GUICtrlCreateMenu("&Options")
    Global $guide = GUICtrlCreateMenuItem("Guide", $options)
    Global $restart = GUICtrlCreateMenuItem("Restart", $options)
    Global $about = GUICtrlCreateMenuItem("About", $options)
    Global $exit = GUICtrlCreateMenuItem("Exit", $options)
    Global $extra = GUICtrlCreateMenu("Extras")
    Global $creator = GUICtrlCreateMenu("CQB", $extra )
    Global $new = GUICtrlCreateMenuItem("custom QP", $creator)
    Global $load = GUICtrlCreateMenuItem("CQ", $creator )
    Global $timer = GUICtrlCreateLabel("", 752, 472, 294, 30, $WS_BORDER)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) )
    GUICtrlSetFont(-1, $iFontSize)
    GUICtrlSetState($timer, $GUI_HIDE)
    Global $info = GUICtrlCreateLabel( $q, 200, 20, 700, 200, $SS_CENTER )
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) )
    $fi = GUICtrlSetFont($info, $iFontSize)
    Global $a = GUICtrlCreateRadio("A)", 100, 210, $WS_EX_CLIENTEDGE)
    $fa = GUICtrlSetFont($a, 15)
    GUICtrlSetResizing(-1,  BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) )
    GUICtrlSetState($a, 16)
    Global $b = GUICtrlCreateRadio("B)", 100, 310 , $WS_EX_CLIENTEDGE)
    $fb = GUICtrlSetFont($b, 15)
    GUICtrlSetResizing(-1,  BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) )
    GUICtrlSetState($b, 16)
    Global $c = GUICtrlCreateRadio("C)", 750, 210 , $WS_EX_CLIENTEDGE)
    $fc = GUICtrlSetFont($c, 15)
    GUICtrlSetResizing(-1,  BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) )
    GUICtrlSetState($c, 16)
    Global $d = GUICtrlCreateRadio( "D) ", 750, 310, $WS_EX_CLIENTEDGE)
    $fd = GUICtrlSetFont($d, 15)
    GUICtrlSetResizing (-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) )
    GUICtrlSetState($d, 16)
    Global $sign = GUICtrlCreateLabel( $file, 420, 480, -1, -1, BitOR ( $SS_CENTER, $WS_BORDER ) )
    GUICtrlSetResizing ( -1, BitOR ( $GUI_DOCKHCENTER, $GUI_DOCKVCENTER ) )
    GUICtrlSetFont($sign, 12)
    Global $yb = GUICtrlCreateRadio("True", 200, 420, 200, 50, $BS_PUSHLIKE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER,$GUI_DOCKSIZE))
    GUICtrlSetFont($yb, 15)
    GUICtrlSetState($yb, 32)
    Global $nb = GUICtrlCreateRadio("False", 700, 420, 200, 50, $BS_PUSHLIKE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER, $GUI_DOCKSIZE))
    GUICtrlSetFont($nb, 15)
    GUICtrlSetState($nb, 32)
    Global $start = GUICtrlCreateButton("Start", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($start, 12)
    Global $valid = GUICtrlCreateButton("Confirm", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($valid, 12)
    GUICtrlSetState($valid, 32)
    GUISetState(@SW_SHOW)
    #EndRegion GUI

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Switch MsgBox(4096 + 4, "Warning", "Are you sure to exit?")
                    Case 6
                        AdlibUnRegister("timer")
                        If Not $qf = "" Then
                            FileClose($file)
                        EndIf
                        Exit
                    Case 7
                        ContinueLoop
                EndSwitch
            Case $start
                ;AdlibRegister("timer")
                ;Global $qf = StringSplit(StringStripWS(FileRead($file), 6), @CRLF, 0)
                ;qloop($file)
        GUICtrlSetData($a, "A) This long string is an example as string that I  want to fit in 4 radio buttons because sometimes it can be that long.")
        GUICtrlSetData($b, "B) This long string is an example as string that I  want to fit in 4 radio buttons because sometimes it can be that long.")
        GUICtrlSetData($c, "C) This long string is an example as string that I  want to fit in 4 radio buttons because sometimes it can be that long.")
        GUICtrlSetData($d, "D) This long string is an example as string that I  want to fit in 4 radio buttons because sometimes it can be that long.")
            Case $restart
                MsgBox(4096, "Warning", 'Normally, your suposed to start something before restarting it.')
                ContinueLoop
            Case $new
                ;GUISetState(@SW_HIDE, $gui)
                ;_CustomNew()
                ContinueLoop
            Case $load
                ;_CustomLoad()
            Case $about
                ;_About()
        EndSwitch
    WEnd
EndFunc   ;Main()

Func timer()
    If $time = 0 Then Global $time = TimerInit()
    Global $diff = TimerDiff($time)
    Global $sec = Int(Mod($diff / 1000, 60))
    Global $min = Int(Mod($diff / 60000, 60))
    Global $hour = Int($diff / 3600000)
    If $sec < 10 Then $sec = "0" & $sec
    If $min < 10 Then $min = "0" & $min
    If $hour < 10 Then $hour = "0" & $hour
    GUICtrlSetData($timer, "Temps: " & $hour & ":" & $min & ":" & $sec)
EndFunc   ;==>timer

Func destroy()
    If FileExists($file) Then
        FileDelete($file)
    EndIf
    DirCreate(@TempDir & "\About")
  FileInstall("C:\test.txt", $file)
EndFunc   ;==>destroy

 

Edited by WilliamasKumeliukas
added more details

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

Thank you mikell, I remember i've use $BS_MULTILINE style before and nothing was changing I don't know why now it does but what I'm trying to do is to adapt the height and width of the radio buttons for different resolutions (when maximized) 

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

thanks but I found better Global $a = GUICtrlCreateRadio("A)", 100, 230, 400, 100, BitOR($BS_MULTILINE, $BS_TOP))

41 minutes ago, mikell said:

Resizing works correctly for me, when changing the "Global $a = ..."  line in your script to this one :

Global $a = GUICtrlCreateRadio("A)", 100, 210, 500, 100, $BS_MULTILINE)

 

I also added $GUI_DOCKAUTO in GUICtrlSetResizing line which seems to help.

 

The only issue remaining is that if the text contains more than x characters then it goes out of bounds and thats what I why I want the radio height and width to be adjusted and reposition radios if height or width is going inside another radio.

I tried searching on this forum for something like this but I get no results relative to what i'm looking for.

Br,

~WIlliamas Kumeliukas

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

WilliamasKumeliukas,

Using my StringSize UDF seems to work quite well:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include "StringSize.au3"

Opt("GUIResizeMode", 802)
Opt("GUICloseOnEsc", 1)

Global $q = "INTRO LINE" & @CRLF & @CRLF & "description of everything until user press start."
Global $iGUIInitSize = 550

Main()

Func Main()
    ;Global $iGUIInitSize = 550
    ;Opt("GUICloseOnEsc", 1)
    Global $gui = GUICreate("example", 1124, 550, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))

    Global $gui_size = WinGetClientSize($gui)
    Global $iFontSize = Int(2 * (.25 + (8 * $gui_size[0] / $iGUIInitSize))) / 2
    Global $timer = GUICtrlCreateLabel("", 752, 472, 294, 30, $WS_BORDER)
    GUICtrlSetBkColor(-1, 0xFF0000)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont(-1, $iFontSize)
    ;GUICtrlSetState($timer, $GUI_HIDE)
    Global $info = GUICtrlCreateLabel($q, 200, 20, 700, 200, $SS_CENTER)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    $fi = GUICtrlSetFont($info, $iFontSize)
    GUICtrlSetBkColor(-1, 0x00FF00)

    Global $a = GUICtrlCreateRadio("A)", 50, 210, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fa = GUICtrlSetFont($a, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($a, 16)
    Global $b = GUICtrlCreateRadio("B)", 50, 310, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fb = GUICtrlSetFont($b, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($b, 16)
    Global $c = GUICtrlCreateRadio("C)", 612, 210, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fc = GUICtrlSetFont($c, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($c, 16)
    Global $d = GUICtrlCreateRadio("D) ", 612, 310, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fd = GUICtrlSetFont($d, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($d, 16)

    Global $sign = GUICtrlCreateLabel("File", 420, 480, -1, -1, BitOR($SS_CENTER, $WS_BORDER))
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($sign, 12)
    Global $yb = GUICtrlCreateRadio("True", 200, 420, 200, 50, $BS_PUSHLIKE)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM)
    GUICtrlSetFont($yb, 15)
    ;GUICtrlSetState($yb, 32)
    Global $nb = GUICtrlCreateRadio("False", 700, 420, 200, 50, $BS_PUSHLIKE)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM)
    GUICtrlSetFont($nb, 15)
    ;GUICtrlSetState($nb, 32)
    Global $start = GUICtrlCreateButton("Start", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($start, 12)
    Global $valid = GUICtrlCreateButton("Confirm", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($valid, 12)
    ;GUICtrlSetState($valid, 32)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Switch MsgBox(4096 + 4, "Warning", "Are you sure to exit?")
                    Case 6
                        Exit
                    Case 7
                        ContinueLoop
                EndSwitch
            Case $start
                $aPos = ControlGetPos($gui, "", $a)
                $sText = "A) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long."
                $aRet = _StringSize($sText, 15, Default, Default, Default, $aPos[2] - 25) ; Allow for radio button in the rectangle
                GUICtrlSetData($a, $aRet[0])
                $sText = "B) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long."
                $aRet = _StringSize($sText, 15, Default, Default, Default, $aPos[2] - 25)
                GUICtrlSetData($b, $aRet[0])
                $sText = "C) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long."
                $aRet = _StringSize($sText, 15, Default, Default, Default, $aPos[2] - 25)
                GUICtrlSetData($c, $aRet[0])
                $sText = "D) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long."
                $aRet = _StringSize($sText, 15, Default, Default, Default, $aPos[2] - 25)
                GUICtrlSetData($d, $aRet[0])
        EndSwitch
    WEnd
EndFunc   ;==>Main

M23

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:

Spoiler

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 comment
Share on other sites

Thank you @Melba23 and @mikell for the help I really appreciate it, I will test it as soon as I get more free time.

@Melba23 , did you test it in maximized state also? I'm just making sure.

 

Thanks again

Br,

~Williamas Kumeliukas

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

@Melba23, I tested with your udf but I though it would  resize both the height and width of the rectangle.

Ive added the text one more time in $sText (because I want to support up to 500 characters in each strings if possible) as shown below:

                $sText = "A) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long. A) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long."
I'm aware its impossible to fit 500 characters in the current font I use so I want it to reduce the font size if it does not fit text inside rectangle.

I hope you understand what I am trying to explain,

Br,

~WilliamasKumeliukas

 

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

WilliamasKumeliukas,

Try this code which dynamically resets the font size each time you resize the GUI:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include "StringSize.au3"

Opt("GUIResizeMode", 802)
Opt("GUICloseOnEsc", 1)

Global $q = "INTRO LINE" & @CRLF & @CRLF & "description of everything until user press start."
Global $iGUIInitSize = 550

Main()

Func Main()
    ;Global $iGUIInitSize = 550
    ;Opt("GUICloseOnEsc", 1)
    Global $gui = GUICreate("example", 1124, 550, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))

    Global $gui_size = WinGetClientSize($gui)
    Global $iFontSize = Int(2 * (.25 + (8 * $gui_size[0] / $iGUIInitSize))) / 2
    Global $timer = GUICtrlCreateLabel("", 752, 472, 294, 30, $WS_BORDER)
    GUICtrlSetBkColor(-1, 0xFF0000)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont(-1, $iFontSize)
    ;GUICtrlSetState($timer, $GUI_HIDE)
    Global $info = GUICtrlCreateLabel($q, 200, 20, 700, 200, $SS_CENTER)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    $fi = GUICtrlSetFont($info, $iFontSize)
    GUICtrlSetBkColor(-1, 0x00FF00)

    Global $a = GUICtrlCreateRadio("A)", 50, 210, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fa = GUICtrlSetFont($a, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($a, 16)
    Global $b = GUICtrlCreateRadio("B)", 50, 310, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fb = GUICtrlSetFont($b, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($b, 16)
    Global $c = GUICtrlCreateRadio("C)", 612, 210, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fc = GUICtrlSetFont($c, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($c, 16)
    Global $d = GUICtrlCreateRadio("D) ", 612, 310, 500, 100, $BS_MULTILINE, $WS_EX_CLIENTEDGE)
    $fd = GUICtrlSetFont($d, 15)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    ;GUICtrlSetState($d, 16)

    Global $sign = GUICtrlCreateLabel("File", 420, 480, -1, -1, BitOR($SS_CENTER, $WS_BORDER))
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($sign, 12)
    Global $yb = GUICtrlCreateRadio("True", 200, 420, 200, 50, $BS_PUSHLIKE)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM)
    GUICtrlSetFont($yb, 15)
    ;GUICtrlSetState($yb, 32)
    Global $nb = GUICtrlCreateRadio("False", 700, 420, 200, 50, $BS_PUSHLIKE)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM)
    GUICtrlSetFont($nb, 15)
    ;GUICtrlSetState($nb, 32)
    Global $start = GUICtrlCreateButton("Start", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($start, 12)
    Global $valid = GUICtrlCreateButton("Confirm", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER))
    GUICtrlSetFont($valid, 12)
    GUICtrlSetState($valid, 32)
    GUISetState(@SW_SHOW)

    $sText = "This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long. "

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Switch MsgBox(4096 + 4, "Warning", "Are you sure to exit?")
                    Case 6
                        Exit
                    Case 7
                        ContinueLoop
                EndSwitch
            Case $start, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; Check for fit each time the control size changes
                ; Get current size of radio label
                $aPos = ControlGetPos($gui, "", $a)
                ; Determine largest font that will fit in the available rectangle
                $sFormattedText = _GetFontSize("A) " & $sText, $aPos)
                ; Set font size for control
                GUICtrlSetFont($a, @extended)
                ; Write formatted text to control
                GUICtrlSetData($a, $sFormattedText)

                $sFormattedText = _GetFontSize("B) " & $sText & $sText, $aPos) ; Make text longer for each control
                GUICtrlSetFont($b, @extended)
                GUICtrlSetData($b, $sFormattedText)

                $sFormattedText = _GetFontSize("C) " & $sText & $sText & $sText, $aPos)
                GUICtrlSetFont($c, @extended)
                GUICtrlSetData($c, $sFormattedText)

                $sFormattedText = _GetFontSize("D) " & $sText & $sText & $sText & $sText, $aPos)
                GUICtrlSetFont($d, @extended)
                GUICtrlSetData($d, $sFormattedText)

        EndSwitch
    WEnd
EndFunc   ;==>Main

Func _GetFontSize($sText, $aPos)

    ; Adjust this as you wish - there is a trade-off between speed and best fit
    For $iSize = 19 to 1 Step -2
        ; Get size of rectangle needed for string at a given font size - wrapping to the available width of the rectangle
        $aRect = _StringSize($sText, $iSize, Default, Default, Default, $aPos[2] - 50)
        ; Now check if height of formatted text will fit into the available rectangle
        If $aRect[3] <= $aPos[3] Then
            ExitLoop
        EndIf
    Next
    ; Return formatted text with required font size in @extended
    Return SetError(0, $iSize, $aRect[0])

EndFunc

As you can see, you get the correct font size regardless of the text length.

M23

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:

Spoiler

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 comment
Share on other sites

First of all Thank you @Melba23 ,

I tried your code it indeed work but I noticed the text is going out of rectangle if u press start then maximize then restore.

I tried working around that little issue for 2hours aldready, I've even tried using GUICtrlSetPos to increase height of each controls by +5 until $aRect[3] <= $aPos[3] (if I understood correctly thats the height needed for $sText to fit in rectangle) but it doesn't seems to work..

Br,

~Williamas Kumeliukas

 

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

WilliamasKumeliukas,

Quote

I noticed the text is going out of rectangle if u press start then maximize then restore

That does not happen when I run the script I posted above - have you made any changes to it?

M23

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:

Spoiler

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 comment
Share on other sites

I didn't but I forgot to say it only occurs to radio $d

*Edit* Yes I did a little change sorry I didn't notice it at first, here is the little change I made last week :

Global $_width = @DesktopWidth / 1.20
Global $_height = @DesktopHeight / 1.30
Global $iGuiWidth = $_width , $iGuiHeight = $_height, $iGuiXPos = (@DesktopWidth / 2) - $iGuiWidth / 2, $iGuiYpos = (@DesktopHeight / 2) - $iGuiHeight / 2

Global $gui = GUICreate("example", $iGuiWidth, $iGuiHeight,$iGuiXPos,$iGuiYpos, BitOR($WS_MAXIMIZEBOX , $WS_MINIMIZEBOX))

~WilliamasKumeliukas

Edited by WilliamasKumeliukas
I forgot some details

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

WilliamasKumeliukas,

Still works for me even with that change.

M23

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:

Spoiler

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 comment
Share on other sites

nevermind I created a new script file to copy ur code in and it work now, I even did compare text with a software to satisfy my curiosity without seeing any differences between both files...

Sorry for wasting your time @melba23

How can I do if I want to be able to maximize, restore and resize without triggering $start?

I am thinking about calling an function on $GUI_EVENT_MAXIMIZE/RESTORE/RESIZED which this function would repeat the same process in ur code but since I'll be in several loops and adding case for $GUI_EVENT in every loops or verifying if GUI size has changed every x ms with adlibregister seems over exagerated, so my question is :  is there an way to "globalize" it?

Br,

~WilliamasKumeliukas

Edited by WilliamasKumeliukas
added question to avoid double-posting

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

I'm having trouble sometimes  with _GetFontSize function returning error 1:

Subscript used on non-accessible variable.:
If $aRect[3] <= $Pos[3] Then
If $aRect^ ERROR
->14:42:13 AutoIt3.exe ended.rc:1

I'm not sure of why it happens but its mostly happening on small size text, especially if Its 1-2 words only, example: using stringsize on for resizing font size of the button True/False will crash immediately with this error,

*Removed*

Sorry for my poor english, I never speak in english, besides here.

Best regards,

~Williamas Kumeliukas

 

Edited by WilliamasKumeliukas
removed 2 useless lines of code

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • 3 weeks later...

After several days playing around in my own Font resizing func I noticed how much I was wrong about it, so I'm back into to using your StringSize UDF @Melba23 . I'm sorry if I tend to be impatient and I hope your willing to continue helping me.

The problem is the same as last time: "C:\example.au3" (213) : ==> Subscript used on non-accessible variable.:
If $aRect[3] <= $aPos[3] Then
If $aRect^ ERROR

*removed*

 2. download the file 1.p I attached (If you prefer using original extension then rename it to 1.txt and in script at line: 29 too )

Br,

Williamas Kumeliukas

1.p

Edited by WilliamasKumeliukas

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

WilliamasKumeliukas,

That script as posted does not even run:

Quote

"M:\Program\Au3 Scripts\test.au3" (237) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If $qf[$i + 7] = 2 Then
If ^ ERROR

If you want help, then post simple, runnable script which shows the problem - not 800+ lines with lots of irrelevant code.

M23

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:

Spoiler

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 comment
Share on other sites

4 hours ago, Melba23 said:

WilliamasKumeliukas,

That script as posted does not even run:

If you want help, then post simple, runnable script which shows the problem - not 800+ lines with lots of irrelevant code.

M23

$qf[$i+7] = 2 error is because the attached file is not in @scriptDir, at line 29 in my code you will see: Global $file = @ScriptDir & "\1.p".

I gave this file because the problem is only occuring when I resize GUI while in qloop function, when you click start in the gui it will going in qloop function.

so just make sure 1.p is in the same folder as the script.

sorry if the script is not simple.

Br,

Williamas kumeliukas

Edited by WilliamasKumeliukas

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

Link to comment
Share on other sites

  • Moderators

WilliamasKumeliukas,

Read what I said above:

Quote

If you want help, then post simple, runnable script which shows the problem - not 800+ lines with lots of irrelevant code.

I repeat: I am NOT prepared to wade through 800+ lines of uncommented code, most of which is totally irrelevant to the problem you are having, to try and get to the bottom of this. YOU provide me with a simple stripped-down version of the script which demonstrates the problem and I will investigate further. Otherwise you are on your own.

M23

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:

Spoiler

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 comment
Share on other sites

23 minutes ago, Melba23 said:

WilliamasKumeliukas,

Read what I said above:

I repeat: I am NOT prepared to wade through 800+ lines of uncommented code, most of which is totally irrelevant to the problem you are having, to try and get to the bottom of this. YOU provide me with a simple stripped-down version of the script which demonstrates the problem and I will investigate further. Otherwise you are on your own.

M23

okay, i'll try to strip it as much I can, sorry for the inconvenience.

Br,

WK

 

Sorry if it's quite challenging to understand me sometimes, there is 2 possible reasons to this:

Spoiler

#1. I am a native French speaker and learned English mainly from chatting with others players in online games.

#2. I have a developmental disorder mainly affecting my social abilities, way of thinking, understanding stuffs and explaining myself in which it can seem ironic of seeing me here, but I been working on getting better every days for an dozens of years now ^_^

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Do not like my dirty code? It's fine, but in my opinion, the dirty codes are unique and I believe it's a good glimpse of how the mind of the person who wrote it thinks, and that, that's what I call a psychological deduction step by step in all its splendor.

~WilliamasKumeliukas

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

×
×
  • Create New...