Change Caret and caret Colour for specific gadget
Posted: Wed Jan 22, 2014 1:39 pm
I have a StringGadget() whose background colour is a murky mustard. The default caret is almost impossible to see, so I would like to force the caret to be jet black.
My experiments didn't achieve this because Windows decides the caret colour contrast, even if a bitmap is used for the caret. So, the compromise would be to make the caret a 'fat block' instead of a slender line. Not too bad, a fat block is easier to see - but two problems:
1) As soon as the StringGadget() is clicked, the default Windows caret (slender line) is restored. If the String Gadget already contains text, we are back to square one - difficult to see the caret.
2) Caret position via the API is controlled with pixel input rather than character count, so placing the caret at the end of the text is tricky.
At the moment, the solution is to change the background colour of the StringGadget(), but..........
My experiments didn't achieve this because Windows decides the caret colour contrast, even if a bitmap is used for the caret. So, the compromise would be to make the caret a 'fat block' instead of a slender line. Not too bad, a fat block is easier to see - but two problems:
1) As soon as the StringGadget() is clicked, the default Windows caret (slender line) is restored. If the String Gadget already contains text, we are back to square one - difficult to see the caret.
2) Caret position via the API is controlled with pixel input rather than character count, so placing the caret at the end of the text is tricky.
At the moment, the solution is to change the background colour of the StringGadget(), but..........
Code: Select all
Enumeration
#Win
#Str
#Car
EndEnumeration
;LoadImage(#Car, "C:\Caret.bmp")
iFlags.i = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
pt.POINT
If OpenWindow(#Win, 0, 0, 300, 100, "Change Caret and Caret Colour?", iFlags)
StringGadget(#Str, 10, 50, 280, 20, "")
;SetGadgetColor(#Str, #PB_Gadget_BackColor, RGB(136,136,064))
DestroyCaret_()
;CreateCaret_(GadgetID(#Str), ImageID(#Car), 8, 16)
CreateCaret_(GadgetID(#Str), #Null, 10, 16)
GetCaretPos_(@pt)
;pt\x = pt\x + 25
;SetCaretPos_(pt\x, pt\y)
SetCaretBlinkTime_(600)
ShowCaret_(GadgetID(#Str))
EndIf
Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
DestroyCaret_()
End