How to change the color and font of a GUI button when I hover mouse pointer over it?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

How to change the color and font of a GUI button when I hover mouse pointer over it?

01 May 2019, 13:23

Please look at this gif-
ram4.gif
ram4.gif (124.57 KiB) Viewed 946 times
In above video you can see that when i bring cursor on any button then it changes the color of that button (perhaps slightly the font and color also). I want to know which part of the codes create such effect in GUI. In fact this is smart clicker program which is quite awesome created by Hellbent. The codes of this program is following-
[Mod edit: Code removed per request by the author.]


I just want to know- is there any kind of command, function or any utility which creates such kind of effect in gui buttons?

Please help and guide. thanks a lot...

Thanks a lot...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: How to change the color and font of a GUI button when I hover mouse pointer over it?

03 May 2019, 13:21

Is there any help regarding it? What is gdip and Bitmap which are used again and again in above codes? please tell...
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
garry
Posts: 1903
Joined: 22 Dec 2013, 12:50

Re: How to change the color and font of a GUI button when I hover mouse pointer over it?

04 May 2019, 01:56

have no answer for GDIP
here just an example with 2 Buttons, if hover then CHANGE FONT
( GUI example for different screensize , not needed here )

Code: Select all

#warn
SetWorkingDir, %A_ScriptDir%
wa:=A_screenwidth
ha:=A_screenHeight
Gui,2:-border
Gui,2: -DPIScale
SS_REALSIZECONTROL := 0x40
Gui,2:Color,Black,Black
Gui,2:Font,s13 cGray,Lucida Console
xx:=100
w:=wa*8/xx, h:=ha*2.8/xx ,dw:=wa*1/xx, dh:=ha*1/xx
x1:=(wa*2)/xx, y1:=ha*1/xx
Gui,2:add,button,x%x1% y%y1% w%w% h%h%            gA1 ,Button-A
x2:=(wa*2)/xx, y2:=ha*5/xx
Gui,2:add,button,x%x2% y%y2% w%w% h%h%   vButtonB gA2 ,Button-B
x :=(wa*10)/xx, y:=ha*10/xx , gw:=wa*25/xx, gh:=ha*20/xx
Gui,2:show,x%x% y%y% w%gw% h%gh%,Hover_Test
OnMessage(0x200, "WM_MOUSEMOVE")
return
;----------------
esc::exitapp
;-------------------------------------------------------------------------------
WM_MOUSEMOVE(wParam, lParam, msg, hwnd) {
	static prev := ""
	MouseGetPos positionX, positionY, hoveredWindow, curr, 
	if(prev != curr) {
		if(prev) {
            Gui,2:Font,s13,Lucida Console
	        Gui,2: font,norm,
	        guicontrol,2:font, %prev%
			prev := ""
		}
		if(curr) {
            Gui,2:Font,s13 ,Courier new
	        Gui,2: font,italic,
	        guicontrol,2:font, %curr%
			prev := curr
		}
	}
}

;----------------
a1:
Gui,2:submit,nohide
r:= a_guicontrol          ;- vVar ( Buttonname )
Mousegetpos,,,,Control      
msgbox, 262208,A ,Clicked Button =%r%`n CTRL=%control%,2
return
;----------------
a2:
Gui,2:submit,nohide
r:= a_guicontrol          ;- vVar ( Buttonname )
Mousegetpos,,,,Control      
msgbox, 262208,B ,Clicked Button =%r%`n CTRL=%control%,2
return
;===================== end script ========================

Example for COLOR BUTTONs

Code: Select all

#Warn
#NoEnv
SendMode,Input
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode,2
SetBatchLines, -1
FileEncoding, UTF-8
Gui,2:default
Gui,2: -DPIScale
SS_REALSIZECONTROL := 0x40
Gui,2:Font,s14 , Verdana
Gui,2:Color,Gray,Black

WinGetPos, TTX, TTY, TTW, TrayHeight, ahk_class Shell_TrayWnd,,,
HA    :=(A_screenheight-TrayHeight)
WA    :=(A_screenwidth)

xx:=100.4
GW    :=(WA*99.9)/xx      ;- width    Gui Width
GH    :=(HA*99  )/xx      ;- height   Gui Height

;------------- example some color buttons -----------
i=0
y   :=(ha*1.01)/xx
x   :=(wa*1.66)/xx
LY1 :=(HA*95  )/xx
w   :=(wa*5   )/xx
h   :=(ha*2.5 )/xx
sect1=Check-XY,Default,YT_SIZE,LAST,QUIT,Youtube,Archive,NL_Archive,UK_Pathe,PT_Oldies,NL_Lubach,US_Oldies,RU_Masha
sect=%sect1%
stringsplit,k,sect,`,
           total:=k0
Gui,2:add,text,section x%x% y%ly1% w0 h0,
 Loop,%total%
    {
    i++
    ck:=k%a_index%
    Gui,2:Add,Progress, x+15   y%ly1% w%w% h%h%  Disabled BackgroundBlue
    if (i>5)
      Gui,2:Add,Text,     xp   yp  wp  hp   cGray    BackgroundTrans Center 0x200 gStart2 ,%ck%
    else
      Gui,2:Add,Text,     xp   yp  wp  hp   cYellow  BackgroundTrans Center 0x200 gStart2 ,%ck%
    }
;---------------------------------------------------

gui,2:show, x0 y0 h%gh% w%gw%,MENU %a_osversion% | %a_ostype% | 64bit=%a_is64bitos% | %wa%*%ha% | %a_username%=%a_isadmin% | %a_computername%
return

Quit:
2GuiEscape:
2GuiClose:
exitapp

Start2:
gui,2:submit,nohide
r:= a_guicontrol
goto,%r%
return

Check-XY:
Default:
YT_SIZE:
LAST:
Youtube:
Archive:
NL_Archive:
UK_Pathe:
PT_Oldies:
NL_Lubach:
US_Oldies:
RU_Masha:
msgbox, 262208,BUTTON-TEST ,%r%,2
return
;=========================================================================
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: How to change the color and font of a GUI button when I hover mouse pointer over it?

07 May 2019, 13:22

just me wrote:
04 May 2019, 04:07
[Class] ImageButton

Thanks dear just me... Your this button class really helped me to create custom buttons. You are really great and awesome!!!!!

Dear just me, is there any such kind of class or function by using that i can create custom edit boxes, radio buttons, check boxes, list view, progress bar, text etc in GUI? Please tell and guide. Thank you dear just me... :clap: :salute:
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Sabestian Caine
Posts: 420
Joined: 12 Apr 2015, 03:53

Re: How to change the color and font of a GUI button when I hover mouse pointer over it?

10 May 2019, 13:59

garry wrote:
04 May 2019, 01:56
have no answer for GDIP
here just an example with 2 Buttons, if hover then CHANGE FONT
( GUI example for different screensize , not needed here )

Code: Select all

#warn
SetWorkingDir, %A_ScriptDir%
wa:=A_screenwidth
ha:=A_screenHeight
Gui,2:-border
Gui,2: -DPIScale
SS_REALSIZECONTROL := 0x40
Gui,2:Color,Black,Black
Gui,2:Font,s13 cGray,Lucida Console
xx:=100
w:=wa*8/xx, h:=ha*2.8/xx ,dw:=wa*1/xx, dh:=ha*1/xx
x1:=(wa*2)/xx, y1:=ha*1/xx
Gui,2:add,button,x%x1% y%y1% w%w% h%h%            gA1 ,Button-A
x2:=(wa*2)/xx, y2:=ha*5/xx
Gui,2:add,button,x%x2% y%y2% w%w% h%h%   vButtonB gA2 ,Button-B
x :=(wa*10)/xx, y:=ha*10/xx , gw:=wa*25/xx, gh:=ha*20/xx
Gui,2:show,x%x% y%y% w%gw% h%gh%,Hover_Test
OnMessage(0x200, "WM_MOUSEMOVE")
return
;----------------
esc::exitapp
;-------------------------------------------------------------------------------
WM_MOUSEMOVE(wParam, lParam, msg, hwnd) {
	static prev := ""
	MouseGetPos positionX, positionY, hoveredWindow, curr, 
	if(prev != curr) {
		if(prev) {
            Gui,2:Font,s13,Lucida Console
	        Gui,2: font,norm,
	        guicontrol,2:font, %prev%
			prev := ""
		}
		if(curr) {
            Gui,2:Font,s13 ,Courier new
	        Gui,2: font,italic,
	        guicontrol,2:font, %curr%
			prev := curr
		}
	}
}

;----------------
a1:
Gui,2:submit,nohide
r:= a_guicontrol          ;- vVar ( Buttonname )
Mousegetpos,,,,Control      
msgbox, 262208,A ,Clicked Button =%r%`n CTRL=%control%,2
return
;----------------
a2:
Gui,2:submit,nohide
r:= a_guicontrol          ;- vVar ( Buttonname )
Mousegetpos,,,,Control      
msgbox, 262208,B ,Clicked Button =%r%`n CTRL=%control%,2
return
;===================== end script ========================

Example for COLOR BUTTONs

Code: Select all

#Warn
#NoEnv
SendMode,Input
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode,2
SetBatchLines, -1
FileEncoding, UTF-8
Gui,2:default
Gui,2: -DPIScale
SS_REALSIZECONTROL := 0x40
Gui,2:Font,s14 , Verdana
Gui,2:Color,Gray,Black

WinGetPos, TTX, TTY, TTW, TrayHeight, ahk_class Shell_TrayWnd,,,
HA    :=(A_screenheight-TrayHeight)
WA    :=(A_screenwidth)

xx:=100.4
GW    :=(WA*99.9)/xx      ;- width    Gui Width
GH    :=(HA*99  )/xx      ;- height   Gui Height

;------------- example some color buttons -----------
i=0
y   :=(ha*1.01)/xx
x   :=(wa*1.66)/xx
LY1 :=(HA*95  )/xx
w   :=(wa*5   )/xx
h   :=(ha*2.5 )/xx
sect1=Check-XY,Default,YT_SIZE,LAST,QUIT,Youtube,Archive,NL_Archive,UK_Pathe,PT_Oldies,NL_Lubach,US_Oldies,RU_Masha
sect=%sect1%
stringsplit,k,sect,`,
           total:=k0
Gui,2:add,text,section x%x% y%ly1% w0 h0,
 Loop,%total%
    {
    i++
    ck:=k%a_index%
    Gui,2:Add,Progress, x+15   y%ly1% w%w% h%h%  Disabled BackgroundBlue
    if (i>5)
      Gui,2:Add,Text,     xp   yp  wp  hp   cGray    BackgroundTrans Center 0x200 gStart2 ,%ck%
    else
      Gui,2:Add,Text,     xp   yp  wp  hp   cYellow  BackgroundTrans Center 0x200 gStart2 ,%ck%
    }
;---------------------------------------------------

gui,2:show, x0 y0 h%gh% w%gw%,MENU %a_osversion% | %a_ostype% | 64bit=%a_is64bitos% | %wa%*%ha% | %a_username%=%a_isadmin% | %a_computername%
return

Quit:
2GuiEscape:
2GuiClose:
exitapp

Start2:
gui,2:submit,nohide
r:= a_guicontrol
goto,%r%
return

Check-XY:
Default:
YT_SIZE:
LAST:
Youtube:
Archive:
NL_Archive:
UK_Pathe:
PT_Oldies:
NL_Lubach:
US_Oldies:
RU_Masha:
msgbox, 262208,BUTTON-TEST ,%r%,2
return
;=========================================================================

Thanks dear garry for your kind support and for these outstanding codes... :clap: :clap:


Dear garry.. Could you please tell me how can I create custom (colorful) edit boxes, radio buttons, check boxes, list views? please help. Thanks garry....
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
garry
Posts: 1903
Joined: 22 Dec 2013, 12:50

Re: How to change the color and font of a GUI button when I hover mouse pointer over it?

10 May 2019, 15:16

have no experience
maybe ask again or advanced search in forum : script&functions , user='just me' , example search for Listview CLASS
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=1081&hilit=Listview+class
example user 'just me' and many others have knowledge , CLASS for different functions, like Listview rows color , different Edit colors etc
Hellbent
Posts: 816
Joined: 23 Sep 2017, 13:34

Re: How to change the color and font of a GUI button when I hover mouse pointer over it?

19 Oct 2019, 05:08

@Sabestian Caine

Were you able to get things figured out?

Return to “Ask For Help”

Who is online

Users browsing this forum: mightysparks, PipeDreams, scriptor2016, Sweetins and 198 guests