Is there a component like TSpeedButton that can receive the Focus? TSpeedButton cannot because it is derived from TGraphicsControl and not from TWinControl. But since the question "How do I make TSpeedButton receive the focus?" must have been asked a Gazillion times over the years, I can't believe that nobody has written a component that solves that problem. But my Google fu left me.

Is there a component like TSpeedButton that can receive the Focus? TSpeedButton cannot because it is derived from TGraphicsControl and not from TWinControl. But since the question "How do I make TSpeedButton receive the focus?" must have been asked a Gazillion times over the years, I can't believe that nobody has written a component that solves that problem. But my Google fu left me.

What I need is TSpeedButton's ability to stay down until pressed again, but it should take the focus and be pressed with the space bar.
This is about VCL only.

Comments

  1. TBitBtn can receive focus, but I think it cannot stay down. If memory serves me right, Raize has a button that can.

    ReplyDelete
  2. Jeroen Wiert Pluimers Indeed: TRzButton has properties AllowAllUp, Down and GroupIndex that implement the same behavior as the corresponding TSpeedButton properties.

    ReplyDelete
  3. OK, I should have mentioned that I don't want a component pack but a single component. And its license must be compatible with GExperts.

    ReplyDelete
  4. After experimenting a bit, I came up with the following possible solutions:
    1. Take TBitBtn, use the Picture of a TSpeedButton in Up and Down state as the Glyph. Works but is a bit ugly
    2. Take a TColorButton (http://www.swissdelphicenter.ch/en/showcode.php?id=1100) and change it's background color depending on whether it's down or not. Could work if I find a colour that looks good.
    3. Take a TBitBtn and use a custom glyph that looks like a round button, again in an Up and Down state. I think that one could work both technically and visually.
    swissdelphicenter.ch - SwissDelphiCenter.ch : ...change a TButton's Color ?

    ReplyDelete
  5. Why not using a TCheckBox? It can receive the focus, toggles on space bar. Regession: Up/Down state is Checked/Unchecked.

    ReplyDelete
  6. Achim Kalwa the standard component would be either Checkbox (AllowAllUp = true) or RadioButton/RadioGroup (AllowAllUp = false). But they are just not as flexible, in particular I can't easily size and arrange them the way I'd like to.

    ReplyDelete
  7. What about a simple TButton and change the Imageindex for Up/Down. This can easily be achieved with a TAction in its OnUpdate event.

    ReplyDelete
  8. Uwe Raabe TButton does not have an Image in Delphi 6. But that's basically my TBitBtn solution.

    ReplyDelete
  9. +Thomas Mueller (dummzeuch I did a quick grep for the word allup
    and found
    TToolbarButton97.SetAllowAllUp
    TcyDBAdvSpeedButton.CMButtonPressed cy librery
    Codebot Class Library @ codebot.org - Open Source Delphi
    in SpeedCtrls; has it too

    and Developer Express Visual Component Library has it too

    All are buttons

    ReplyDelete
  10. Thomas Mueller i just saw that
    Downloads of the Codebot Controls have been removed
    So since it was free get in touch i will send you the source

    P.S they are all searched on D7

    ReplyDelete
  11. Thomas Mueller One more TFlatButton
    I have all the sources - free.

    ReplyDelete
  12. shlomo abuisak I found the TFlatButton sources on GitHub (https://github.com/cust/delphi/tree/master/FlatStyle%20Component) , but apparently they require quite a lot of additional units and don't compile without changes (somebody adapted them to XE5, breaking backwards compatibility). I have a solution based on TBitBtn now. I'll see how far I get with that. If it works out, I'll blog about it. If not, I'll be contacting you regarding the sources.

    ReplyDelete
  13. Attila Kovacs​ ich sollte definitiv öfter google.de verwenden, aber normalerweise ist es umgekehrt.

    ReplyDelete
  14. Thomas Mueller I found an old archive of FlatStyle components dated from 2001 with sources. You can get the library from here github.com - pitfiend/FlatStyle

    ReplyDelete
  15. We can suggest TscButton control from our StyleControls VCL (http://www.almdev.com). You can set TscButton.StyleKind = scbsToolButton, TscButton.CanFocused = True. This control has GroupIndex, AllowAllUp, RepeatClick, DropDownMenu, SplitButton and many others properties to get full analogue of speed button (tool button) with focus. Also, of course it has perfect themes and VCL Styles support!

    ReplyDelete
  16. Attila Kovacs I just tried the code you linked to. Yes, it works when klicking the mouse and as long as the focus stays on the button. But the button comes up again when pressed with the space bar or moving the focus to some other control. So, no solution either. Thanks for the hint anyway.

    ReplyDelete
  17. Attila Kovacs your source works BUT as i recall the button pressed is changing graphically to show the button is actually DOWN.
    I used this feature a long time ago.

    ReplyDelete
  18. Attila Kovacs I tried that too: Same problem when the focus moves to a different control. Also, I made some changes to my original code (see new blog post). I'm pretty satisfied with the way it works now. It's simple and easy to understand.

    ReplyDelete
  19. Thomas Mueller I tried to add your source as a component by putting on a form.
    I get >>>> invalid class typecast.
    Obviously i registered the component on the pallet.
    Any idea? D10.2.1

    ReplyDelete
  20. Attila Kovacs As per Thomas Mueller demo this is what i ment

    ReplyDelete

Post a Comment