Recent

Author Topic: TBCButtonFocus and focus  (Read 517 times)

dseligo

  • Hero Member
  • *****
  • Posts: 1246
TBCButtonFocus and focus
« on: March 06, 2024, 02:30:42 pm »
I am not able to set TBCButtonFocus to visually show that it has focus.
Is there a way that TBCButtonFocus handle focus by itself?

I am using ActiveControlChanged event of Screen to set border style, but I complicated it too much. I would like to simplify this, but first I want to check if it possible to achieve it in some other way.

lainz

  • Hero Member
  • *****
  • Posts: 4520
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: TBCButtonFocus and focus
« Reply #1 on: March 06, 2024, 03:29:13 pm »
I am not able to set TBCButtonFocus to visually show that it has focus.
Is there a way that TBCButtonFocus handle focus by itself?

I am using ActiveControlChanged event of Screen to set border style, but I complicated it too much. I would like to simplify this, but first I want to check if it possible to achieve it in some other way.

Check in the test folder:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.BCButtonFocus1PaintButton(Sender: TObject);
  2. var
  3.   button: TBCButtonFocus;
  4. begin
  5.   button := TBCButtonFocus(Sender);
  6.   button.Canvas.Brush.Style := bsClear;
  7.   button.Canvas.Pen.Color := clRed;
  8.   if button.Focused then
  9.     button.Canvas.Rectangle(3, 3, button.Width-3, button.Height-3);
  10. end;  

dseligo

  • Hero Member
  • *****
  • Posts: 1246
Re: TBCButtonFocus and focus
« Reply #2 on: March 06, 2024, 04:09:23 pm »
Great, thank you. It is simpler than solution I had.

I will set events on creating forms, something like that:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   DataModule1.SetMyForm(Self);
  4. end;
  5.  
  6. ...
  7.  
  8. procedure TDataModule1.SetBCButtonFocusFocus(Sender: TObject);
  9. var button: TBCButtonFocus;
  10. begin
  11.   If not (Sender is TBCButtonFocus) then
  12.     Exit;
  13.  
  14.   button := TBCButtonFocus(Sender);
  15.   if button.Focused then
  16.   begin
  17.     button.Canvas.Brush.Style := bsClear;
  18.     button.Canvas.Pen.Color := clRed;
  19.     button.Canvas.Rectangle(3, 3, button.Width - 3, button.Height - 3);
  20.   end;
  21. end;
  22.  
  23. procedure TDataModule1.SetMyForm(AForm: TForm);
  24. var iControl: Integer;
  25. begin
  26.   For iControl := 0 to AForm.ControlCount - 1 do
  27.     If AForm.Controls[iControl] is TBCButtonFocus then
  28.       (AForm.Controls[iControl] as TBCButtonFocus).OnPaintButton := @SetBCButtonFocusFocus;
  29. end;

I see this works too in OnPaintButton event (until now I used it like this but in ActiveControlChanged of Screen):
Code: Pascal  [Select][+][-]
  1. ...
  2.   button := TBCButtonFocus(Sender);
  3.   if button.Focused then
  4.     button.StateNormal.Border.Style := bboSolid
  5.   else
  6.     button.StateNormal.Border.Style := bboNone;
  7. end;

lainz

  • Hero Member
  • *****
  • Posts: 4520
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: TBCButtonFocus and focus
« Reply #3 on: March 07, 2024, 12:30:40 am »
Great  :)

 

TinyPortal © 2005-2018