JohnOne Posted May 8, 2014 Posted May 8, 2014 Yes. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
ReconX Posted May 8, 2014 Author Posted May 8, 2014 in what way? I cannot seem to get anything like that to work, although I am a noob tho. Im trying to change the background color on mouseover and change it back to normal on when the mouse is removed from the Label.
Moderators Melba23 Posted May 8, 2014 Moderators Posted May 8, 2014 ReconX,Many ways to do this - here is one of the simplest:#include <GUIConstantsEx.au3> Global $fOver = False $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("", 10, 10, 100, 100) GUICtrlSetBkColor($cLabel, 0xFF0000) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $aCInfo = GUIGetCursorInfo($hGUI) If $aCInfo[4] = $cLabel Then If $fOver = False Then GUICtrlSetBkColor($cLabel, 0x00FF00) $fOver = True EndIf Else If $fOver = True Then GUICtrlSetBkColor($cLabel, 0xFF0000) $fOver = False EndIf EndIf WEndPlease ask if you have any questions. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ReconX Posted May 8, 2014 Author Posted May 8, 2014 Thank you that simplified everything ten folds, your are a true gentleman and scholar. Could you help me out by explaining some of the tags so I could understand them more? Such as; $aCInfo & $fOver.
ReconX Posted May 8, 2014 Author Posted May 8, 2014 Also, would I have to repeat the coding for each individual label?
Moderators Melba23 Posted May 8, 2014 Moderators Posted May 8, 2014 ReconX,$fOver is a flag that shows whether the cursor is over the label. That way we only change the colour once when the cursor enter/leaves the label - if we do not use the flag the label is recoloured on every pass and we get flashing like this:#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("", 10, 10, 100, 100) GUICtrlSetBkColor($cLabel, 0xFF0000) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $aCInfo = GUIGetCursorInfo($hGUI) If $aCInfo[4] = $cLabel Then GUICtrlSetBkColor($cLabel, 0x00FF00) Else GUICtrlSetBkColor($cLabel, 0xFF0000) EndIf WEnd$aCInfo is the array returned by the GUIGetCursorInfo function - look in the Help file to see what it contains. I use a sort of Hungarian notation for my variables so I know what each is expected to contain (a = array; i = integer; f = flag; etc).And yes you would need to code for each label. But what exactly are you trying to do? There might be a better way to code if you explain the overall problem. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ReconX Posted May 8, 2014 Author Posted May 8, 2014 (edited) That clears things up a little more. xD I am trying to make a GUI that gives you the option to download certain software. The only thing similar to what I am trying to do, that I have used is the IOBitToolbox which is the program in the image. See how "Win Fix" is highlighted along with the image and text? That's what I am trying to achieve with the mouseover. Another thing is, that when I duplicated the code for another label, it started to flicker a little bit, is that some sort of overload for the $fOver string? Edited May 8, 2014 by ReconX
Gianni Posted May 8, 2014 Posted May 8, 2014 Hi ReconX also ...> this post has some nice examples Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Moderators Melba23 Posted May 8, 2014 Moderators Posted May 8, 2014 ReconX,As I suspected, there is a much simpler way to code something like that: expandcollapse popup#include <GUIConstantsEx.au3> ; An array to hold the label ControlIDs Global $aLabel[5] ; A variable to show the last label which changed colour Global $iLastLabel = 0 $hGUI = GUICreate("Test", 500, 500) For $i = 0 To 4 $aLabel[$i] = GUICtrlCreateLabel("", 0, 0 + (100 * $i), 500, 100) GUICtrlSetBkColor($aLabel[$i], 0x00FF00) 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 4 ; If we are over a new label If $aCInfo[4] = $aLabel[$i] And $iLastLabel <> $i Then ; Recolour previos label GUICtrlSetBkColor($aLabel[$iLastLabel], 0x00FF00) ; colour current label GUICtrlSetBkColor($aLabel[$i], 0xFF0000) ; Store this label $iLastLabel = $i ; No point in looking further ExitLoop EndIf Next WEndIt always helps to explain exactly what you are trying to do when posting - it saves people suggesting less than optimal solutions and gets you a working solution much quicker. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ReconX Posted May 8, 2014 Author Posted May 8, 2014 Thank you Melba23, you are awesome, and by far the best person I have came across on this forum. I am currently messing around with the code and tweaking it to my liking. I assume that each label would have to have another label to input the text over it?
Moderators Solution Melba23 Posted May 8, 2014 Moderators Solution Posted May 8, 2014 ReconX, I assume that each label would have to have another label to input the text over itNo, just add the text to the label itself - perhaps using an array of the required text like this:expandcollapse popup#include <GUIConstantsEx.au3> ; An array to hold the label ControlIDs Global $aLabel[5] ; A variable to show the last label which changed colour Global $iLastLabel = 0 ; An array to hold the label text Global $aText[5] = ["First label", "Second label", "Third label", "Fourth label", "Fifth label"] $hGUI = GUICreate("Test", 500, 500) For $i = 0 To 4 $aLabel[$i] = GUICtrlCreateLabel($aText[$i], 0, 0 + (100 * $i), 500, 100) GUICtrlSetBkColor($aLabel[$i], 0x00FF00) 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 4 ; If we are over a new label If $aCInfo[4] = $aLabel[$i] And $iLastLabel <> $i Then ; Recolour previos label GUICtrlSetBkColor($aLabel[$iLastLabel], 0x00FF00) ; colour current label GUICtrlSetBkColor($aLabel[$i], 0xFF0000) ; Store this label $iLastLabel = $i ; No point in looking further ExitLoop EndIf Next WEndAll clear. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JohnOne Posted May 8, 2014 Posted May 8, 2014 Always wondered why there is no WM_MOUSEOVER message while there is WM_MOUSEHOVER. Bonkers. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Malkey Posted May 8, 2014 Posted May 8, 2014 Without For-Next. #include <GUIConstantsEx.au3> Example() Func Example() Local $hGui, $x, $y, $b[5] $hGui = GUICreate("Hover control to change its background", 400, 400) $x = GUICtrlCreateLabel("Label x", 10, 10, 50) $y = GUICtrlCreateLabel("Label y", 10, 30, 50) GUICtrlCreateButton("Button", 10, 60) GUICtrlCreateEdit("", 10, 100, 110, 150) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch $a = GUIGetCursorInfo($hGui) If $b[4] <> $a[4] Then GUICtrlSetBkColor($b[4], 0xFFFFFF) ; White $b = $a GUICtrlSetBkColor($a[4], 0xFF0000) ; Red in hex colour format 0xRRGGBB EndIf WEnd GUIDelete() EndFunc ;==>Example
Terenz Posted May 8, 2014 Posted May 8, 2014 (edited) Malkey nice example but if you want to "color" by $variable like only $x or $y instead of everything? Edited May 8, 2014 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength
Malkey Posted May 8, 2014 Posted May 8, 2014 Malkey nice example but if you want to "color" by $variable like only $x or $y instead of everything? @ Terenz An example:- #include <GUIConstantsEx.au3> Example() Func Example() Local $hGui, $x, $y, $b[5] $hGui = GUICreate("Hover control to change its background", 400, 400, -1, -1, -1) $x = GUICtrlCreateLabel("Label x", 10, 10, 50) $y = GUICtrlCreateLabel("Label y", 10, 30, 50) GUICtrlCreateButton("Button", 10, 60) GUICtrlCreateEdit("", 10, 100, 110, 150) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 $a = GUIGetCursorInfo($hGui) Select Case GUIGetMsg() = $GUI_EVENT_CLOSE ExitLoop Case ($a[4] = $x Or $a[4] = 0) And ($b[4] <> $a[4]) ; "Or $a[4] = 0" must appear at least once in multiple Cases GUICtrlSetBkColor($b[4], 0xFFFFFF) ; White $b = $a GUICtrlSetBkColor($a[4], 0xFF0000) ; Red in hex colour format 0xRRGGBB Case $a[4] = $y And ($b[4] <> $a[4]) ; "Or $a[4] = 0" not needed (already exists in above Case) GUICtrlSetBkColor($b[4], 0xFFFFFF) ; White $b = $a GUICtrlSetBkColor($a[4], 0x0000FF) ; Blue in hex colour format 0xRRGGBB EndSelect WEnd EndFunc ;==>Example
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now