Jump to content

Two different text sizes in a string.


 Share

Recommended Posts

I want a title and a description on the button. I want the Title to obviously be bigger than the description. Is there a way to do that? Below is my attempt at it. xD

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>

; An array to hold the label ControlIDs
Global $aLabel[6]
; A variable to show the last label which changed colour
Global $iLastLabel = 0
Global $aText[6] = ["Malwarebytes Removal Tool", "Second label", "Third label", "Fourth label", "Fifth label", "Sixth label"]
Global $aSecondary[6] = ["Bump", "Grump", " ", " ", " ", " "]

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

For $i = 0 To 5
    $aLabel[$i] = GUICtrlCreateLabel($aText[$i] & @CRLF & $aSecondary[$i], 0, 0 + (50 * $i), 450, 45, BitOr($SS_CenterImage, $SS_Center))
    GUICtrlSetBkColor($aLabel[$i], $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont($aText[1], 13, 800)
    GUICtrlSetFont($aSecondary[1], 9.5, 800)

 Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Get cursor info
    $aCInfo = GUIGetCursorInfo($hGUI)
    ; loop through the label array to see which one is under the cursor
    For $i = 0 To 5
        ; If we are over a new label
        If $aCInfo[4] = $aLabel[$i] And $iLastLabel <> $i Then
            ; Recolour previos label
            GUICtrlSetBkColor($aLabel[$iLastLabel], $GUI_BKCOLOR_TRANSPARENT)
            ; colour current label
            GUICtrlSetBkColor($aLabel[$i], 0xFF0000)
            ; Store this label
            $iLastLabel = $i
            ; No point in looking further
            ExitLoop
        EndIf
    Next

WEnd

Also, the $SS_CenterImage doesn't allow both the strings to be centered to the button, is there a way to do that also without it becoming one line?

Edited by ReconX
Link to comment
Share on other sites

  • Moderators

ReconX,

Not too difficult - use 2 labels: ;)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

; An array to hold the label ControlIDs
Global $aLabel[6]
; A variable to show the last label which changed colour
Global $iLastLabel = 0
Global $aText[6] = ["Malwarebytes Removal Tool", "Second label", "Third label", "Fourth label", "Fifth label", "Sixth label"]
Global $aSecondary[6] = ["Bump", "Grump", " ", " ", " ", " "]

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

For $i = 0 To 5
    ; Create the main title label
    $aLabel[$i] = GUICtrlCreateLabel($aText[$i], 0, 0 + (50 * $i), 450, 45, $SS_Center)
    GUICtrlSetBkColor($aLabel[$i], $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont($aLabel[$i], 13, 800)
    ; Now create a secondary label to hold the subtitle
    $cSec = GUICtrlCreateLabel($aSecondary[$i], 0, 20 + (50 * $i), 450, 45, $SS_Center)
    GUICtrlSetBkColor($cSec, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont($cSec, 9.5, 800)
 Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aLabel[0]
            ConsoleWrite("Hit" & @CRLF)

    EndSwitch

    ; Get cursor info
    $aCInfo = GUIGetCursorInfo($hGUI)
    ; loop through the label array to see which one is under the cursor
    For $i = 0 To 5
        ; If we are over a new label
        If $aCInfo[4] = $aLabel[$i] And $iLastLabel <> $i Then
            ; Recolour previos label
            GUICtrlSetBkColor($aLabel[$iLastLabel], $GUI_BKCOLOR_TRANSPARENT)
            ; colour current label
            GUICtrlSetBkColor($aLabel[$i], 0xFF0000)
            ; Store this label
            $iLastLabel = $i
            ; No point in looking further
            ExitLoop
        EndIf
    Next

WEnd
All clear? :)

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

@M23 was faster.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>

; An array to hold the label ControlIDs
Global $aLabel1[6], $aLabel2[6]
; A variable to show the last label which changed colour
Global $iLastLabel = 0
Global $aText[6] = ["Malwarebytes Removal Tool", "Second label", "Third label", "Fourth label", "Fifth label", "Sixth label"]
Global $aSecondary[6] = ["Bump", "Grump", "", "", "", ""]

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

For $i = 0 To 5
    $aLabel1[$i] = GUICtrlCreateLabel($aText[$i], 0, (50 * $i), 500, 45, BitOr($SS_CenterImage, $SS_Center))
    GUICtrlSetBkColor($aLabel1[$i], $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont($aLabel1[$i], 14, 800, 0, "Arial", 4)

    $aLabel2[$i] = GUICtrlCreateLabel($aSecondary[$i], (StringLen($aText[$i]) + StringLen($aSecondary[$i])) * 5.25, (50 * $i), 500, 45, BitOr($SS_CenterImage, $SS_Center))
    GUICtrlSetFont($aLabel2[$i], 7, 400, 0, "Arial", 5)
    GUICtrlSetBkColor($aLabel2[$i], $GUI_BKCOLOR_TRANSPARENT)
 Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Get cursor info
    $aCInfo = GUIGetCursorInfo($hGUI)
    ; loop through the label array to see which one is under the cursor
    For $i = 0 To 5
        ; If we are over a new label
        If ($aCInfo[4] = $aLabel1[$i] Or $aCInfo[4] = $aLabel2[$i]) And $iLastLabel <> $i Then
            ; Recolour previos label
            GUICtrlSetBkColor($aLabel1[$iLastLabel], $GUI_BKCOLOR_TRANSPARENT)
            ; colour current label
            GUICtrlSetBkColor($aLabel1[$i], 0xFF0000)
            ; Store this label
            $iLastLabel = $i
            ; No point in looking further
            ExitLoop
        EndIf
    Next

WEnd

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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