Recent

Author Topic: [Solved] Changing the button color in a ribbon  (Read 966 times)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] Changing the button color in a ribbon
« on: December 25, 2020, 10:24:03 pm »
I have created this ribbon with BGRA Controls.
The panels are defined as TBCPanel. The buttons are defined as TBCButton.


Every time I click on a button that opens a new part of the ribbon I add 1 to the tag of that panel.
I do this so I know which TBCPanel is active.


With this next procedure I activate and deactivate the correct part of the ribbon.
Code: Pascal  [Select][+][-]
  1. procedure TForm_Lint.Lint_Aanzetten(mTag: Integer);
  2. // mTag keeps track of which level of the ribbon is visible
  3. // 0 = Main Ribbon
  4. // 1 = 1 form is open, ribbon 0 Does not work
  5. // 2 = 2 forms open, ribbon  0 & 1 do not work
  6. // 3 = 3 forms open, ribbon 0,1 & 2 do not work. Etc...
  7. var i: integer;
  8. begin
  9.   for i := 0 to ComponentCount-1 do begin
  10.     if mTag <> 99 then
  11.       if Components[i].InheritsFrom(TBCPanel) then begin
  12.         TBCPanel(Components[i]).Enabled := Components[i].Tag = mTag;
  13.       end;
  14.   end;
  15. end;     // Lint_Aanzetten

How can I change the colours of the non-active parts of the ribbon so that it is more clear which part of the ribbon is actually active?

For demonstration purpose let's say:
Code: Pascal  [Select][+][-]
  1. IF TBCPanel is not active THEN
  2.   Change all colours of the TBCButtons in that TBCPanel to RED
  3. ELSE
  4.   Change all colours of the TBCButtons in that TBCPanel to BLUE;
« Last Edit: December 26, 2020, 01:54:36 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

Soner

  • Sr. Member
  • ****
  • Posts: 328
Re: Changing the button color in a ribbon
« Reply #1 on: December 26, 2020, 12:13:05 am »
I would make it so:
Code: Pascal  [Select][+][-]
  1.     IF TBCPanel is not active THEN
  2.       for i:=0 to TBCPanelX.Controlcount-1 do
  3.         if TBCPanel.Controls[i] is TBCButton then
  4.            (TBCPanel.Controls[i] as TBCButton).Color:=RED
  5.  
  6.     ELSE
  7.       for i:=0 to TBCPanelX.Controlcount-1 do
  8.         if TBCPanel.Controls[i] is TBCButton then
  9.            (TBCPanel.Controls[i] as TBCButton).Color:=BLUE
  10.  

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Changing the button color in a ribbon
« Reply #2 on: December 26, 2020, 01:53:53 am »
Thanks..
It's a bit crude but it works.


Full code is now
Code: Pascal  [Select][+][-]
  1. procedure TForm_Lint.Lint_Aanzetten(mTag: Integer);
  2. var i, j: integer;
  3. begin
  4.   for i := 0 to ComponentCount-1 do begin
  5.     if mTag <> 99 then
  6.       if Components[i].InheritsFrom(TBCPanel) then begin
  7.         TBCPanel(Components[i]).Enabled := Components[i].Tag = mTag;
  8.         if TBCPanel(Components[i]).Enabled = True then begin
  9.           TBCPanel(Components[i]).Background.Color := $00F1F1F1;
  10.           for j := 0 to TBCPanel(Components[i]).Controlcount-1 do
  11.             begin
  12.               if TBCPanel(Components[i]).Controls[j] is TBCButton then begin
  13.                 (TBCPanel(Components[i]).Controls[j] as TBCButton).StateNormal.Background.Color := $00F1F1F1;
  14.                 (TBCPanel(Components[i]).Controls[j] as TBCButton).StateHover.Background.Color := $00CDCDCD;
  15.                 (TBCPanel(Components[i]).Controls[j] as TBCButton).StateClicked.Background.Color := $00B0B0B0;
  16.               end;  // if
  17.             end;  // for
  18.           end  // if true
  19.         else begin
  20.           TBCPanel(Components[i]).Background.Color := $00666666;
  21.           for j := 0 to TBCPanel(Components[i]).Controlcount-1 do begin
  22.             if TBCPanel(Components[i]).Controls[j] is TBCButton then begin
  23.               (TBCPanel(Components[i]).Controls[j] as TBCButton).StateNormal.Background.Color := $00666666;
  24.               (TBCPanel(Components[i]).Controls[j] as TBCButton).StateHover.Background.Color := $00666666;
  25.               (TBCPanel(Components[i]).Controls[j] as TBCButton).StateClicked.Background.Color := $00666666;
  26.             end;  // if
  27.           end;  // for
  28.         end;  // if else
  29.       end;
  30.   end;
  31. end;     // Lint_Aanzetten
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

 

TinyPortal © 2005-2018