Hello, Everyone,
I have a GUI with a bunch of text and I want to underline that text whenever my mouse pointer hovers over that text. Anyone know if this is possible and, if so, how to implement it?
Thanks for any help you can provide!
Underline Text in GUI when pointer hovers over text
Re: Underline Text in GUI when pointer hovers over text
I figured it out, but it requires a bit of a hack.
The hack is that it requires checking mouse coordinates (and adding 25 for the title bar) to see if it's over the text. If you have margins within that region, the text will underline even when you're not directly over it. You can minimize that by splitting up each line of text into its own control. Now, if you wanted to set some other type of control, you'd simply do "If A_GuiControl = MyButton", but that doesn't work with text, apparently; instead, A_GuiControl is blank when you mouse over text. Anyways, so the above code works, but with the drawback that I mentioned.
Code: Select all
Gui, New
Gui, Add, Text, vMyText, Text to be underlined when moused over
Gui, Show
OnMessage(0x200, "Underline")
Underline()
{
Sleep 50
MouseGetPos, MouseX, MouseY
GuiControlGet, MyText, Pos
If (MouseX > MyTextX) and (MouseY > (25*(A_ScreenDPI/96) + MyTextY)) and (MouseX < (MyTextX + MyTextW)) and (MouseY < (25*(A_ScreenDPI/96) + MyTextY + MyTextH))
Gui, Font, underline
Else
Gui, Font, norm
GuiControl, Font, MyText
}
Re: Underline Text in GUI when pointer hovers over text
That's awesome! I'll give it a go. Do you happen to know how to change the pointer to the pointing hand that appears after you're hovering over a link?
Thanks a lot!
Thanks a lot!
Re: Underline Text in GUI when pointer hovers over text
Based on Osprey's source, and the hacky way: you can put a hidden link control beneath the text control and respectively show/hide them depending on whether or not the mouse pointer is actually currently hovers them:
Code: Select all
text := "Text to be underlined when moused over"
Gui, New
Gui, Margin, 30, 30
Gui, Add, Text, xm ym vV0, % text
Gui, Add, Link, xm ym hp wp vV1 Hidden, % "<a id=""A"">" . text . "</a>"
Gui, Show
OnMessage(0x200, "Underline")
return
Underline() {
static __i := 0
CoordMode, Mouse, Client ; [EDIT]
Sleep 50
MouseGetPos, __x, __y
GuiControlGet, __pos, Pos, V0
; __v := 25*(A_ScreenDPI/96) + __posY
__v := __posY ; [EDIT]
If ((__x > __posX) and (__y > __v) and (__x < (__posX + __posW)) and (__y < (__v + __posH))) {
if not (__i) {
GuiControl, Hide, V0
GuiControl, Show, V1
__i := 1
}
} else {
if (__i) {
GuiControl, Show, V0
GuiControl, Hide, V1
__i := 0
}
}
}
Re: Underline Text in GUI when pointer hovers over text
Yeah, using Gui, Add, Link may be more suitable for him than what I came up with. It wasn't clear that he wanted something like a link.
FWIW, what I came up with works well for tooltips, if anyone similarly has a need to display tooltips over text or other controls (including disabled controls) that don't work with the standard GuiControl method.
FWIW, what I came up with works well for tooltips, if anyone similarly has a need to display tooltips over text or other controls (including disabled controls) that don't work with the standard GuiControl method.
Re: Underline Text in GUI when pointer hovers over text
It's not an actual link that I wanted, but rather just the link select pointer. Nonetheless, this all helps a lot so I thank you guys a lot!! I thoroughly appreciate it!
Have an awesome day!
Have an awesome day!