Sign in to follow this  
Followers 0
z0mgItsJohn

LabelClickOnEvent?...

6 posts in this topic

Well I'm Trying To Make A Script That Has A GUI And The GUI Has Something Like Hyperlinks And When You Click One Of The "Hyperlinks" It Executes A Function.. How In The World Would I Go About Doing This xD..

Thanks In Advance! =3

- John


Latest Projects :- New & Improved TCP Chat

Share this post


Link to post
Share on other sites



use GUICtrSetOnEvent

a label is a GUI control so it will work.

Share this post


Link to post
Share on other sites

Here is an example of another method which could be adapted for sections in a control (such as a word in an edit box) if you want to, its a bit messy but it works.

Replace the message box with whatever action you want.

#include <Misc.au3>
$GUI = GUICreate("Some GUI",200,50)
;variables for position of label for easy reading
$LabelX = 5
$LabelY = 5
$LabelW = 56
$LabelH = 11

$Label = GUICtrlCreateLabel("Some Label",$LabelX,$LabelY,$LabelW,$LabelH)
GUISetState()

While GUIGetMsg()<>-3
    Sleep(2)
    $Pos = GUIGetCursorInfo($GUI)
    If (_IsPressed("01") And $Pos[0]>=$LabelX And $Pos[0]<=$LabelX+$LabelW And $Pos[1]>=$LabelY And $Pos[1]<=$LabelY+$LabelH) Then
        MsgBox(0,"Click","You Clicked the Label!")
    EndIf
WEnd

_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

#include <GUIConstantsEx.au3>

Global $Label[4][2] = [["",""], ["", "autoitscript.com"], ["", "/forum/index.php?"], ["", "/autoit3/downloads.shtml"]]

$hGui = GUICreate("Autoit Links")
For $i = 1 To 3
    Local $sAdress = "http://www." & $Label[1][1]
    If $i > 1 Then $sAdress = "http://www." & $Label[1][1] & $Label[$i][1]
    $Label[$i][0] = GUICtrlCreateLabel($sAdress, 5, ($i * 25) - 15, 360, 20)
    GUICtrlSetFont(-1, Default, Default, 4)
Next    
GUISetState(@SW_SHOW, $hGui)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Label[1][0] To $Label[3][0]
            ShellExecute(GUICtrlread($msg))
    EndSwitch       

    $GGCI = GUIGetCursorInfo($hGui)
    Switch $GGCI[4]
        Case $Label[1][0] To $Label[3][0]
            If $GGCI[4] <> $Label[0][0] Then
                GUICtrlSetColor($Label[0][0], 0x000000)
                GUICtrlSetFont($Label[0][0], Default, Default, 4)
                GUICtrlSetColor($GGCI[4], 0x0000FF)
                GUICtrlSetFont($GGCI[4], 11, 700, 6)
                $Label[0][0] = $GGCI[4]

            EndIf
        Case Else
            GUICtrlSetColor($Label[0][0], 0x000000)
            GUICtrlSetFont($Label[0][0], Default, Default, 4)
            $Label[0][0] = $GGCI[4]
    EndSwitch
WEnd

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

Thank You!!! ^.^

Here's A Little Function I Made In Case Someone Else Might Wanna Use It..

; Function : _LabelClickOnEvent

Func _LabelClickOnEvent ($Control_ID, $Event, $Size = '9', $Weight = '400', $Attribute = '4', $Fontname = '', $Color = '0x0000FF', $Bk_Color = $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont ($Control_ID, $Size, $Weight, $Attribute, $Fontname)
GUICtrlSetColor ($Control_ID, $Color)
GUICtrlSetBkColor ($Control_ID, $Bk_Color)
GUICtrlSetOnEvent ($Control_ID, $Event)
EndFuncoÝ÷ ØÚ-y8^
çÚº[Oj¶¦z׫°Æ¤xK¢G*^®X§*.­ÇÅ©©à.Ý«­¢+Ø%¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì)=ÁÐ ÌäíU%=¹Ù¹Ñ5½Ìäì°ÌäìÄÌäì¤((ÀÌØíU$ôU%
ÉÑ ÌäíQÍÐÌäì°ÌäìØÌÌäì°ÌäìÌÔÌäì°Ìäì´ÄÌäì°Ìäì´ÄÌäì°Ìäì´ÄÌäì°ÌäìÄÈàÌäì¤)U%MÑ=¹Ù¹Ð ÀÌØíU%}Y9Q}
1=M°Ìäí}á¥ÐÌäì¤(ÀÌØí1°ôU%
Ñɱ
ÉÑ1° Ìäí5Í   ½àÌäì°ÌäìÄÀÌäì°ÌäìÄÀÌäì°ÌäìÐÌÌäì°ÌäìÄÐÌäì¤)}1±
±¥­=¹Ù¹Ð ÀÌØí1°°Ìäí}5Í ½àÌäì¤)U%MÑMÑÑ¡M]}M!=¤()]¡¥± ÌäìÄÌäì¤)M±À ÌäìÄÔÀÌäì¤)]¹()Õ¹}5Í    ½à ¤)5Í ½à ÌäìÀÌäì°ÌäíQÍÐÌäì°Ìäí1±
±¥­=¹Ù¹ÐüÌäì°ÌäìÀÌäì¤)¹Õ¹()Õ¹}1±
±¥­=¹Ù¹Ð ÀÌØí
½¹Ñɽ±}%°ÀÌØíٹаÀÌØíM¥éôÌäìäÌäì°ÀÌØí]¥¡ÐôÌäìÐÀÀÌäì°ÀÌØíÑÑÉ¥ÕÑôÌäìÐÌäì°ÀÌØí½¹Ñ¹µôÌäìÌäì°ÀÌØí
½±½ÈôÌäìÁàÀÀÀÁÌäì°ÀÌØí    ­}
½±½ÈôÀÌØíU%}   -
=1=I}QI9MAI9P¤)U%
ÑɱMѽ¹Ð ÀÌØí
½¹Ñɽ±}%°ÀÌØíM¥é°ÀÌØí]¥¡Ð°ÀÌØíÑÑÉ¥ÕÑ°ÀÌØí½¹Ñ¹µ¤)U%
ÑɱMÑ
½±½È ÀÌØí
½¹Ñɽ±}%°ÀÌØí
½±½È¤)U%
ÑɱMÑ   ­
½±½È ÀÌØí
½¹Ñɽ±}%°ÀÌØí    ­}
½±½È¤)U%
ÑɱMÑ=¹Ù¹Ð ÀÌØí
½¹Ñɽ±}%°ÀÌØíٹФ)¹Õ¹()Õ¹}á¥Ð ¤)á¥Ð)¹Õ¹

- John


Latest Projects :- New & Improved TCP Chat

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi, here's another using on event with a modified version of your function.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $Label[4][2] = [["",""], ["", "autoitscript.com"], ["", "/forum/index.php?"], ["", "/autoit3/downloads.shtml"]]

$hGui = GUICreate("Autoit Links")
GUISetOnEvent($GUI_EVENT_CLOSE, "Event")
For $i = 1 To 3
    Local $sAdress = "http://www." & $Label[1][1]
    If $i > 1 Then $sAdress = "http://www." & $Label[1][1] & $Label[$i][1]
    $Label[$i][0] = GUICtrlCreateLabel($sAdress, 5, ($i * 25) - 15, 360, 20)
    GUICtrlSetOnEvent(-1, "Event")
    _LabelSet($Label[$i][0], Default, 0x0000FF, Default, Default, 4)
Next    
GUISetState(@SW_SHOW, $hGui)

While 1
    Sleep(100)
    $GGCI = GUIGetCursorInfo($hGui)
    Switch $GGCI[4]
        Case $Label[1][0] To $Label[3][0]
            If $GGCI[4] <> $Label[0][0] Then
                _LabelSet($Label[0][0], Default, 0x0000FF, Default, Default, 4)  
                _LabelSet($GGCI[4], Default, 0x0000FF, 11, 700, 6) 
                $Label[0][0] = $GGCI[4]
            EndIf
        Case Else
            _LabelSet($Label[0][0], Default, 0x0000FF, Default, Default, 4)
            $Label[0][0] = $GGCI[4]
    EndSwitch
WEnd

Func Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Label[1][0] To $Label[3][0]
            ShellExecute(GUICtrlread(@GUI_CtrlId))
    EndSwitch
EndFunc 

Func _LabelSet($cID, $iBkClr = Default, $iClr = Default, $iSz = Default, $iWt = Default, $iAttr = Default, $sFont = "")
    GUICtrlSetFont ($cID, $iSz, $iWt, $iAttr, $sFont)
    GUICtrlSetColor ($cID, $iClr)
    GUICtrlSetBkColor ($cID, $iBkClr)
EndFunc

Cheers

Edit: Set the links to blue.. lol

Edited by smashly

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