Sign in to follow this  
Followers 0
Dazzler

How do I set a label border color (different to SetColor)

10 posts in this topic

Gurus,

I can set a label's ink color with: GUICtrlSetColor

I can set a label's background colour with: GUICtrlSetBkColor

But using $WS_BORDER, the border color is set as the ink color.

Can I have the border color as another color again?

Share this post


Link to post
Share on other sites



Could you provide a small reproducer please.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

The font color is purple

The background is grey

The border is black

I'd like to change the border to my selection

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

$gui = guicreate("TEST", 200, 100)

$label = guictrlcreatelabel("LABEL", 5, 5, 80, 20, $WS_BORDER)

GUICtrlSetBkColor(-1, 0xb0c4de)

GUICtrlSetColor(-1, 0x483d8d)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

endselect

WEnd

Share this post


Link to post
Share on other sites

Please use [autoit][/autoit] tags when posting AutoIt code please. Search the forum for WM_CTLCOLOR, though I could be wrong.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Here a workaround (fast hack):

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

_GDIPlus_Startup()
Global Const $STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0
$hGUI = GUICreate("TEST", 200, 100)

$idLabel = GUICtrlCreateLabel("LABEL", 5, 5, 80, 20)
GUICtrlSetBkColor(-1, 0xb0c4de)
GUICtrlSetColor(-1, 0x483d8d)
ConsoleWrite(_GDIPlus_CreateCtrlBorder($hGUI, $idLabel, 0xFF5D233E) & @LF)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
        Case $idLabel
            MsgBox(0, "Test", "Label was clicked")
    EndSwitch
WEnd


Func _GDIPlus_CreateCtrlBorder($HWnd, $idCtrl, $iColor, $iPenSize = 1, $bETCHED = False) ;coded by UEZ build 2013-01-15
    If Not Int($iColor) Then Return SetError(1, 0, 0)
    Local $aPos = ControlGetPos($HWnd, "", $idCtrl)
    If @error Then Return SetError(2, 0, 0)
    Local $hPen = _GDIPlus_PenCreate(0, $iPenSize)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aPos[2] + 2, "int", $aPos[3] + 2, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($aResult[6]), $iD = 1
    If $bETCHED Then
        $iD = -Floor($iPenSize / 2 - 1 * ($iPenSize = 1))
        _GDIPlus_PenSetColor($hPen, 0xFFFEFEFE)
        _GDIPlus_PenSetWidth($hPen, $iPenSize * 2)
        _GDIPlus_GraphicsDrawRect($hCtxt, $iPenSize, $iPenSize, $aPos[2] - $iPenSize + 1, $aPos[3] - $iPenSize + 1, $hPen)
    EndIf
    _GDIPlus_PenSetColor($hPen, $iColor)
    _GDIPlus_PenSetWidth($hPen, $iPenSize)
    _GDIPlus_GraphicsDrawRect($hCtxt, Int($iPenSize / 2), Int($iPenSize / 2), $aPos[2] - $iPenSize + $iD + (Not ($bETCHED > 0)), $aPos[3] - $iPenSize + $iD + (Not ($bETCHED > 0)), $hPen)
    Local $iPic = GUICtrlCreatePic("", $aPos[0] - 1, $aPos[1] - 1, $aPos[2] + 1, $aPos[3] + 1)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($aResult[6])
    $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)
    If $hB Then _WinAPI_DeleteObject($hB)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($aResult[6])
    _WinAPI_DeleteObject($hHBitmap)
    Return 1
EndFunc   ;==>_GDIPlus_CreateCtrlBorder

Br,

UEZ

Edited by UEZ
1 person likes this

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

An more easy workaround:

#include <GUIConstantsEx.au3>

$gui = GUICreate("TEST", 200, 100)

$label = CreateBorderLabel("LABEL", 5, 5, 80, 20, 0xA00000, 2, 0x201)
GUICtrlSetBkColor(-1, 0xb0c4de)
GUICtrlSetColor(-1, 0x483d8d)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $label
            MsgBox(0, "Test", "Label was clicked")
    EndSelect

WEnd

GUIDelete()
Exit

Func CreateBorderLabel($sText, $iX, $iY, $iW, $iH, $iColor, $iPenSize = 1, $iStyle = -1, $iStyleEx = 0) ;coded by funkey 2013
    Global $nID = GUICtrlCreateLabel("", $iX - $iPenSize, $iY - $iPenSize, $iW + 2 * $iPenSize, $iH + 2 * $iPenSize, 0)
    GUICtrlSetBkColor(-1, $iColor)
    GUICtrlCreateLabel($sText, $iX, $iY, $iW, $iH, $iStyle, $iStyleEx)
    Return $nID
EndFunc   ;==>CreateBorderLabel
Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

Cheers guys n gals

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Funkey: very nice workaround. I had been using:

#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$form1million = GUICreate("form 1 million", 300, 238)

$left1 = 50
$top1 = 100
$width1 = 200
$height1 = 40

$borderBackLabelA = GUICtrlCreateLabel("", $left1, $top1, $width1, $height1)
GUICtrlSetBkColor($borderBackLabelA, 0x0000ff)
GUICtrlSetState($borderBackLabelA, $GUI_DISABLE)

$borderBackLabelB = GUICtrlCreateLabel("", $left1 + 2, $top1 + 2, $width1 - 4, $height1 - 4)
GUICtrlSetBkColor($borderBackLabelB, 0xff00ff)
GUICtrlSetState($borderBackLabelB, $GUI_DISABLE)

$borderBackLabelC = GUICtrlCreateLabel("", $left1 + 4, $top1 + 4, $width1 - 8, $height1 - 8)
GUICtrlSetBkColor($borderBackLabelC, 0x00ff00)
GUICtrlSetState($borderBackLabelC, $GUI_DISABLE)

$realLabel = GUICtrlCreateLabel("CABLE resources (creative alternative but low-end)", $left1 + 6, $top1 + 6, $width1 - 12, $height1 - 12)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $realLabel
Exit

EndSwitch
WEnd

Edited by lorenkinzel

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

loren, funkey,

That's so cool I made this function from your code and allow for more user definition...

#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>

$form1million = GUICreate("form 1 million", 300, 300)

local $lbl010    =    _ColoredLabelBorders(9,3,50,20,200,200)

ConsoleWrite('$lbl010 ctrlid = ' & $lbl010 & @LF)

local $lbl020    =    guictrlcreatelabel('',0,270,300,25,$ss_sunken)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $lbl010
            ConsoleWrite('Clicked on label $lbl010' & @LF)
        case $lbl020
            ConsoleWrite('Clicked on label $lbl020' & @LF)
    EndSwitch
WEnd

func _ColoredLabelBorders($numcol, $thickness, $left, $top, $width, $height)

    ; $numcol        =    # of colored border rings
    ; $thickness    =    Thickness of each border color in pixels
    ; $left            =    left side of control
    ; $top            =    top of control
    ; $width        =     width of control
    ; $height        =    height of control

    if $numcol < 1 or $numcol > 9 then return seterror(1)

    local $colortbl[10] = ['',0xff0000,0x00ff00,0x0000ff,0xff00ff,0x222200,0xf0aa50,0xf0000f,0x0ffff0,0xaa00aa]

    for $1 = 1 to $numcol
        guictrlcreatelabel('',$left+$1*$thickness,$top+$1*$thickness,$width-$1*($thickness*2),$height-$1*($thickness*2))
        guictrlsetbkcolor(-1,$colortbl[$1])
    Next
    global $ctrlid = guictrlcreatelabel('',$left+$1*$thickness,$top+$1*$thickness,$width-$1*($thickness*2),$height-$1*($thickness*2))
    ;_winapi_setparent($ctrlid,$form1million)

    return $ctrlid

endfunc

Only problem is that I cannot action the label returned from the function.

kylomas

edit: additional data...when I create the label before the loop I can action the control, but the color of the control is the last color

I set. Don't have time to fuck with this anymore tonight...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Fixed it...not exactly sure why it works when the bordered ctrl is the bottom most control but it does...

#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>

local $ctrlid

$form1million = GUICreate("form 1 million", 300, 300)

local $lbl010    =    _ColoredLabelBorders(9,4,50,20,200,200)

ConsoleWrite('$lbl010 ctrlid = ' & $lbl010 & @LF)

local $lbl020    =    guictrlcreatelabel('',0,270,300,25,$ss_sunken)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $lbl010
            ConsoleWrite('Clicked on label $lbl010' & @LF)
        case $lbl020
            ConsoleWrite('Clicked on label $lbl020' & @LF)
    EndSwitch
WEnd

func _ColoredLabelBorders($numcol, $thickness, $left, $top, $width, $height)

    ; $numcol        =    # of colored border rings
    ; $thickness    =    Thickness of each border color in pixels
    ; $left            =    left side of control
    ; $top            =    top of control
    ; $width        =     width of control
    ; $height        =    height of control

    if $numcol < 1 or $numcol > 9 then return seterror(1)

    local $colortbl[10] = ['',0xff0000,0x00ff00,0x0000ff,0xff00ff,0x222200,0xf0aa50,0xf0000f,0x0ffff0,0xaa00aa]

    $ctrlid = guictrlcreatelabel('',$left,$top,$width,$height)

    for $1 = 1 to $numcol
        guictrlcreatelabel('',$left+$1*$thickness,$top+$1*$thickness,$width-$1*($thickness*2),$height-$1*($thickness*2))
        guictrlsetbkcolor(-1,$colortbl[$1])
    Next

    guictrlcreatelabel('',$left+$1*$thickness,$top+$1*$thickness,$width-$1*($thickness*2),$height-$1*($thickness*2))

    return $ctrlid

endfunc

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
Sign in to follow this  
Followers 0