Jump to content
Sign in to follow this  
CodyBarrett

Label styles

Recommended Posts

CodyBarrett

iive looked through 18 pages on this subject.. i know ive seen it before in on script on here or another but can't remember where...

i would like to know how IF the mouse position is over top of a label then put a border around the label and when it leaves the controls possition it resests it to what it was before

here is an example of a GUI and label..

anyone know how to do this? i prefer to use labels over buttons but i want it to look like a button.. labels i find are more customizable

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

Opt ('GUIoneventmode',1)
$GUI = GUICreate ( 'Example', 300, 300, -1, -1, -2138570616)
$Label = GUICtrlCreateLabel ('TEST', 50, 50, 200, 200, $SS_CENTER)
GUICtrlSetColor (-1, 0xFFFFFF)
GUICtrlSetFont (-1, 50, 900)
GUICtrlSetBkColor (-1, 0x2e2e2e)
GUISetOnEvent ($GUI_EVENT_CLOSE,'_exit')
GUISetState()

While 1

WEnd

Func _exit ()
    
    Exit

EndFunc

Share this post


Link to post
Share on other sites
Authenticity

Maybe something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

Opt ('GUIoneventmode',1)

$pt = DllStructCreate($tagPOINT)
$fSet = False

$GUI = GUICreate ( 'Example', 300, 300, -1, -1, -2138570616)
$Label = GUICtrlCreateLabel ('TEST', 50, 50, 200, 200, $SS_CENTER)
$hLabel = GUICtrlGetHandle(-1)

GUICtrlSetColor (-1, 0xFFFFFF)
GUICtrlSetFont (-1, 50, 900)
GUICtrlSetBkColor (-1, 0x2e2e2e)
GUISetOnEvent ($GUI_EVENT_CLOSE,'_exit')
GUISetState()

While 1
    $aPos = MouseGetPos()
    DllStructSetData($pt, 1, $aPos[0])
    DllStructSetData($pt, 2, $aPos[1])
    
    $hWnd = _WinAPI_WindowFromPoint($pt)
    
    If $hWnd = $hLabel Then
        If Not $fSet Then
            GUICtrlSetBkColor($Label, 0xe2e2e2)
            GUICtrlSetColor ($Label, 0)
            $fSet = True
        EndIf
    Else
        If $fSet Then
            GUICtrlSetBkColor($Label, 0x2e2e2e)
            GUICtrlSetColor ($Label, 0xFFFFFF)
            $fSet = False
        EndIf
    EndIf
    Sleep(50)
WEnd

Func _exit ()
    GUIDelete()
    Exit
EndFunc

Share this post


Link to post
Share on other sites
CodyBarrett

well.. that makes the color change... what im looking for is having a black label... with a white border around it.. i can do that.. but it erases my text when it happens andy other ideas TY anyway Authenticity

Share this post


Link to post
Share on other sites
Authenticity

Using GDIPlus.au3:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

Opt ('GUIoneventmode',1)

_GDIPlus_Startup()

$pt = DllStructCreate($tagPOINT)
$fSet = False

$GUI = GUICreate ( 'Example', 300, 300, -1, -1, -2138570616)
$Label = GUICtrlCreateLabel ('TEST', 50, 50, 200, 200, $SS_CENTER)
$hLabel = GUICtrlGetHandle(-1)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hLabel)
$hPen = _GDIPlus_PenCreate(0, 10)

GUICtrlSetColor (-1, 0xFFFFFF)
GUICtrlSetFont (-1, 50, 900)
GUICtrlSetBkColor (-1, 0x2e2e2e)
GUISetOnEvent ($GUI_EVENT_CLOSE,'_exit')
GUISetState()

While 1
    $aPos = MouseGetPos()
    DllStructSetData($pt, 1, $aPos[0])
    DllStructSetData($pt, 2, $aPos[1])
   
    $hWnd = _WinAPI_WindowFromPoint($pt)
   
    If $hWnd = $hLabel Then
        If Not $fSet Then
            _GDIPlus_PenSetColor($hPen, 0xFFFFFFFF)
            _GDIPlus_GraphicsDrawRect($hGraphics, 0, 0, 200, 200, $hPen)
            $fSet = True
        EndIf
    Else
        If $fSet Then
            _GDIPlus_PenSetColor($hPen, 0xFF2E2E2E)
            _GDIPlus_GraphicsDrawRect($hGraphics, 0, 0, 200, 200, $hPen)
            $fSet = False
        EndIf
    EndIf
    Sleep(50)
WEnd

Func _exit ()
    GUIDelete()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Share this post


Link to post
Share on other sites
Melba23

CodyBarrett,

Is this any help?:

#include <GUIConstantsEx.au3>

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

GUISetBkColor(0x8080FF, $hGUI)

$hlabel_2 = GUICtrlCreateLabel("Test", 15, 15, 90, 90)
GUICtrlSetBkColor(-1, 0xFF8080)

GUISetState()

$fFlag = False

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    $aInfo = GUIGetCursorInfo($hGUI)
    If $aInfo[4] = $hLabel_2 And $fFlag = False Then
        $sContent = GUICtrlRead($hLabel_2)
        GUICtrlDelete($hlabel_2)
        $hlabel_1 = GUICtrlCreateLabel("", 10, 10, 100, 100)
        GUICtrlSetBkColor(-1, 0xFFFFFF)
        $hLabel_2 = GUICtrlCreateLabel($sContent, 15, 15, 90, 90)
        GUICtrlSetBkColor(-1, 0x000000)
        GUICtrlSetColor(-1, 0xFFFFFF)
        $fFlag = True
    ElseIf $aInfo[4] <> $hLabel_2 And $fFlag = True Then
        $sContent = GUICtrlRead($hLabel_2)
        GUICtrlDelete($hlabel_1)
        GUICtrlDelete($hlabel_2)
        $hLabel_2 = GUICtrlCreateLabel($sContent, 15, 15, 90, 90)
        GUICtrlSetBkColor(-1, 0xFF8080)
        GUICtrlSetColor(-1, 0x000000)
        $fFlag = False
    EndIf 
    
WEnd

M23


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

 

Share this post


Link to post
Share on other sites
CodyBarrett

sorry Authenticity im not ready for GDI+ yet ;)

and THANK YOU Melba23 that was exactly what i was looking for lmao ^_^

EDIT

and yet.. haha isn't there an easyer way other than deleteing the controls...

Edited by CodyBarrett

Share this post


Link to post
Share on other sites
Authenticity

lol ;]

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>

Opt ('GUIoneventmode',1)

_GDIPlus_Startup()

$pt = DllStructCreate($tagPOINT)
$fSet = False
$fFlash = True

$GUI = GUICreate ( 'Example', 300, 300, -1, -1, -2138570616)
$Label = GUICtrlCreateLabel ('TEST', 50, 50, 200, 200, $SS_CENTER)
$hLabel = GUICtrlGetHandle(-1)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hLabel)
$hPen = _GDIPlus_PenCreate(0, 10)

GUICtrlSetColor (-1, 0xFFFFFF)
GUICtrlSetFont (-1, 50, 900)
GUICtrlSetBkColor (-1, 0x2e2e2e)
GUISetOnEvent ($GUI_EVENT_CLOSE,'_exit')
GUISetState()

While 1
    $aPos = GUIGetCursorInfo()
   
    $Ctrl = $aPos[4]
   
    If $Ctrl = $Label Then
        If Not $fSet Then
            _GDIPlus_PenSetColor($hPen, 0xFFFFFFFF)
            _GDIPlus_GraphicsDrawRect($hGraphics, 0, 0, 200, 200, $hPen)
            AdlibEnable('_FlashWindow', 500)
            $fSet = True
        EndIf
    Else
        If $fSet Then
            AdlibDisable()
            _GDIPlus_PenSetColor($hPen, 0xFF2E2E2E)
            _GDIPlus_GraphicsDrawRect($hGraphics, 0, 0, 200, 200, $hPen)
            $fSet = False
        EndIf
    EndIf
    Sleep(50)
WEnd

Func _exit ()
    GUIDelete()
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func _FlashWindow()
    $fFlash = Not $fFlash
    
    If $fFlash Then
        _GDIPlus_PenSetColor($hPen, 0xFFFFFFFF)
        _GDIPlus_GraphicsDrawRect($hGraphics, 0, 0, 200, 200, $hPen)
    Else
        _GDIPlus_PenSetColor($hPen, 0xFF2E2E2E)
        _GDIPlus_GraphicsDrawRect($hGraphics, 0, 0, 200, 200, $hPen)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
CodyBarrett

ugh.... D: GDI+!!!!! nuuuuu lol ill look through it ^_^ thanks anyway haha

Share this post


Link to post
Share on other sites
Melba23

CodyBarrett,

Look - no deletes! :-)

#include <GUIConstantsEx.au3>

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

GUISetBkColor(0x8080FF, $hGUI)

$hlabel_1 = GUICtrlCreateLabel("", 10, 10, 100, 100)
GUICtrlSetBkColor(-1, 0x8080FF)
$hlabel_2 = GUICtrlCreateLabel("Test", 15, 15, 90, 90)
GUICtrlSetBkColor(-1, 0xFF8080)

GUISetState()

$fFlag = False

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    $aInfo = GUIGetCursorInfo($hGUI)
    If $aInfo[4] = $hLabel_2 And $fFlag = False Then
        GUICtrlSetBkColor($hlabel_1, 0xFFFFFF)
        GUICtrlSetBkColor($hlabel_2, 0x000000)
        GUICtrlSetColor($hlabel_2, 0xFFFFFF)
        $fFlag = True
    ElseIf $aInfo[4] <> $hLabel_2 And $fFlag = True Then
        GUICtrlSetBkColor($hlabel_1, 0x8080FF)
        GUICtrlSetBkColor($hlabel_2, 0xFF8080)
        GUICtrlSetColor($hlabel_2, 0xFFFFFF)
        $fFlag = False
    EndIf 
    
WEnd

M23


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

 

Share this post


Link to post
Share on other sites
CodyBarrett

haha i figured that out 5 mins before you posted this.. BUT! i have another problem.. using this in a For loop... inside a while loop... make a flicker ^_^ because i have an array of labels and thats why i didn't want to delete them... but this array is causseing a flicker... a CONSTANT flicker

Share this post


Link to post
Share on other sites
GEOSoft

Hmmmm. This is interesting and I'm not sure if it's expected behaviour or a bug. I thought you could do what you wanted using Styles however if you set the styles as below the text doesn't display.

#include<StaticConstants.au3>
GUICreate("Test GUI")
$hLabel = GUICtrlCreateLabel("TEST LABEL", 10, 10, 150, 20)
$hLabel1 = GUICtrlCreateLabel("TEST LABEL White", 10, 40, 150, 20, BitOr($GUI_SS_DEFAULT_LABEL,$SS_WHITEFRAME))
$hLabel2 = GUICtrlCreateLabel("TEST LABEL Black", 10, 80, 150, 20, BitOr($GUI_SS_DEFAULT_LABEL,$SS_BLACKFRAME))
GUISetState()
While 1
    If GUIGetMsg() = -3 Then Exit
Wend

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
CodyBarrett

yeah... thats why i made this topic D':... it doesn't even allow you to set the text after you change the style...

Share this post


Link to post
Share on other sites
GEOSoft

yeah... thats why i made this topic D':... it doesn't even allow you to set the text after you change the style...

And I just checked it with the MS control tool and it does the same thing so I can assume it's normal behavior which seems somewhat stupid. Maybe it just doesn't work with the XP theme?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
martin

..and if you have lots of labels you only need one label fo rthe border.

#include <GUIConstantsEx.au3>
#include <windowsconstants.au3>
#include <staticconstants.au3>

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

GUISetBkColor(0x8080FF, $hGUI)
Global $hlabel[5],$lastlabel
For $n = 0 To 4
    $hlabel[$n] = GUICtrlCreateLabel("Test " & $n + 1, 15, 15 + 100 * $n, 90, 90)
    GUICtrlSetBkColor(-1, 0xFF8080)
Next

$hlabelBorder = GUICtrlCreateLabel("", 10, 10, 100, 100, BitOR($GUI_SS_DEFAULT_LABEL, $WS_CLIPSIBLINGS))
GUICtrlSetBkColor(-1, 0xFFFFFF);8080FF)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState()

$fFlag = False
$LastLabel = 0
While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $aInfo = GUIGetCursorInfo($hGUI)
    If Not @error Then
        If $aInfo[4] <> $LastLabel Then
            Switch $aInfo[4]
                Case $hlabel[0] To $hlabel[4]
                    If $LastLabel <> 0 Then
                        GUICtrlSetBkColor($LastLabel, 0xFF8080)
                        GUICtrlSetColor($LastLabel, 0)
                    EndIf
                    GUICtrlSetColor($aInfo[4], 0xFFFFFF)
                    GUICtrlSetBkColor($aInfo[4], 0)
                    $lp = ControlGetPos($hGUI, "", $aInfo[4])
                    ControlMove($hGUI, "", $hlabelBorder, $lp[0] - 5, $lp[1] - 5)
                    GUICtrlSetState($hlabelBorder, $GUI_SHOW)
                    $LastLabel = $aInfo[4]
                Case $hlabelBorder
                   ;ConsoleWrite("border" & @CRLF)
                Case Else
                    If $LastLabel <> 0 Then HideBorder()

            EndSwitch

        EndIf
    Else
        If $LastLabel <> 0 Then HideBorder()
    EndIf

WEnd


Func HideBorder()
    GUICtrlSetBkColor($LastLabel, 0xFF8080)
    GUICtrlSetColor($LastLabel, 0)
    GUICtrlSetState($hlabelBorder, $GUI_HIDE)
    $LastLabel = 0
EndFunc  ;==>HideBorder

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
CodyBarrett

holy... thank you martin ^_^ that works now

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.