Transparent Button that can receive focus lazarus / 31-LCL ---------------------------------------------------------------------- CCRDude · 2015-05-19 09:34 Hi there, I'm looking for a transparent button that can receive focus (because I aim to make my software to visually impaired users, where screen reader software reads the caption of the focused control). That rules out TSpeedButton and TLabel based approaches. Dozens of custom controls in Lazarus or even the bloated CodeTyphon all seem to be based on them. TButton and TBitBtn do not have a Flat/Transparent property, nor does it seem simple to add one. A TButtonControl descendant with BS_OWNERDRAW might be the right direction, but I'm not sure how to implement that LCL-compatible (made some steps using WM_DRAWITEM, but as far as I understand, I should go for LM_ messages). PS I'M asking this on the German Delphi-PRAXiS forum as well, but this place might be better when looking for a platform independent solution ---------------------------------------------------------------------- Blaazen · 2015-05-19 11:02 It's not so difficult to create your own component. It must be: - TCustomControl descendant - ControlStyle := ControlStyle - [csNoFocus];  //in constructor and maybe some accesibility settings (I don't have much experience with it) AccessibleRole := larButton;  //in constructor ---------------------------------------------------------------------- Michl · 2015-05-19 13:20 You can also use a TBCButton from BGRAControls. There you can set the styles (StateNormal.Background.Style, StateHover.Background.Style, StateClicked.Background.Style) to bbsClear (and Form.DoubleBuffered:=True). Thats it. [Edit] Forget my note. You need a TWinControl, not a TGraphicControl. ---------------------------------------------------------------------- ChrisF · 2015-05-19 14:11 Concerning accessibility, any solution that is not natively a TWinControl (descendant) won't work for Windows. Basically, that means that everything which is "painted" (i.e. graphical controls) is purely ignored with screen readers. And even in this case (i.e. TWinControl), there are some issues with TWinControl descendants. The "AccessibleRole" property proposed by Blaazen should be theoretically the correct solution. Except that it's not implemented in the LCL for Windows (and probably not for Linux too, though I'm not sure - only an OSX support ?). Plus, I'm not sure there is really a simple and "transparent" solution for graphical controls like TLabel, TImage, ... The accessible fields within the TControl component (i.e. AccessibleRole, AccessibleValue and AccessibleDescription) are just completely ignored. There has already been a discussion about this problem (i.e. accessibility for non TWinControls), and I've proposed a possible "workaround". I even intended to implement a basic approach of the accessibility in the LCL for Windows, but I must confess I've currently postponed this project. If interested, I could post an updated version of my "workaround" with a sample: just tell me. Please note however that it doesn't really propose a "solution" for graphical controls; just some functionalities to "get around" this problem in some cases, and the support of accessible fields of TControls for Windows. The Lazarus accessibility wiki webpage: http://wiki.freepascal.org/LCL_Accessibility The concerned topic with my "workaround" tool (last post of the topic): http://forum.lazarus.freepascal.org/index.php/topic,25635.msg155927.ht ml Another solution proposed by fredvs (sorry, not tested; anyway, I guess he could detailed his solution better than I could do): http://wiki.lazarus.freepascal.org/sak ---------------------------------------------------------------------- CCRDude · 2015-05-20 11:53 Many thanks Blazen, while I actually wanted to avoid re-inventing the wheel, I went ahead and did that anyway now. And even more thanks ChrisF! That gives me way more insight than expected So far, I just wanted to cover the "basics", but four work allows me to provide way more value. If you indeed have an updated version, yes, please share it ---------------------------------------------------------------------- ChrisF · 2015-05-20 15:15 I've uploaded an updated version of my workaround tool (version beta 0.5.2). See the concerned topic (http://forum.lazarus.freepascal.org/i ndex.php/topic,25635.msg155927.html) for the "WAccessibilityTmp-v0.5.2.zip" file. Attached to this post, another sample specifically dedicated to a custom control based upon the TCustomControl class, and "faked" to be a pushbutton for screen readers. Just 2 issues for this sample (I'm speaking here only of the accessibility part, of course), concerning the mouse: 1/ It's currently impossible to tell to screen readers if/when the "faked button" is pressed 2/ The text of the control (i.e. the caption of the "faked button") is read by screen readers only when the mouse cursor is exactly over the text itself, and not when it's over another part of the custom control. I don't know if it can be fixed easily using only the LCL. (This doesn't concern the indications given to screen readers, when the control is focused using keyboard inputs: it's OK in this case). A possible solution would be to have a visible static text control covering all the custom control area (which could be a problem in your case): see the sample coming with WAccessibilityTmp for instance. There are 2 possible ways in this sample for having a image description recognized by screen readers. Or eventually, may be to process directly Windows messages (like WM_NCHITTEST)...