- This topic has 7 replies, 3 voices, and was last updated 12 years, 2 months ago by Support.
-
AuthorPosts
-
August 13, 2012 at 11:20 am #35307SzakiLaciParticipant
Hi,
Can you please give me a tip, how to Set color on a TsBitBtn, if Skin is turned off (Active=False)?
Why?
It's a must at my program, to see, where is the current focus, if someone is pressing the enter.
But on some earlier (8+ years) pc > skin must be turned off, to be able to run the program fast.
(or simply the user does not like it for whatever reason…)
Earlier I've wrote some code for a single TButton, overriding it.
But since I've changed all component to AlphaControls, it does not work fine.
I have problems with normal TsButton repaint … (sometimes big buttons are invisible),
so changing ALL buttons to BitBtns would be a better choice and also gives the possibility to put some nice icons next to the Caption.
[attachment=5805:colored_button.png]
How can I do this ?
Thanks 🙂
August 14, 2012 at 7:09 am #48760HamiltonParticipantAFAIK you cannot do this; to achieve a similar result I've always used a TsSpeedButton on a TsPanel; if you make the panel have your desired color then set the TsSpeedButton to be flat and transparent then voila you have colored buttons. Please note though that this does *not* work for all skins (ref: [topic='7109']here[/topic]).
Good luck!
PS I have no idea how you managed to color a TBitBtn! As I understand it, that control uses the Windows comctl library to render the control and that means the color comes from the Windows theme – so to change the colour you would have to put a panel over the button, reimplement all the mouseover and click funtionality, redo the borders, redraw the text etc – all of which would be horrible! How did you do this?!
Regards,
Hamilton
August 14, 2012 at 7:10 am #48761HamiltonParticipantNB: For the panel make sure the SkinData.CustomColor flag is set to TRUE.
August 15, 2012 at 9:59 am #48772SzakiLaciParticipant'Hamilton' wrote:…how you managed to color a TBitBtn…
I did NOT. That's why I'm asking it here. I did it with a normal TButton.
And yes, I had to “rewrite” the TButton component by Copy-Paste 😀
Code:TButton = class(TButton)
…
published
property Color;
end;procedure TsButton.DrawButton(Rect: TRect; State: UINT);
…
FCanvas.Brush.Color := Color; //instead of clBtnFaceBut I don't wanna mess up with AlphaControls, since
– they are a bit more complicated,
– and every time a new version is out, I had to make those changes again and again,
– or if I'm overriding it the same way I did with normal TButton > I would loose the improvements with new versions.
That' why I'm asking here, maybe there's a simple solution form me.
[Of course it would be the easies and most logic way, if Serge would put those few lines into the component itself,
but I can not force him to create a “FocusedColor” property.] :a8:
August 15, 2012 at 12:13 pm #48773SzakiLaciParticipantTemporarily I've made following changes at
Code:unit sBitBtn;
…
type
TsBitBtn = class(TTntBitBtn)
private
…
FFocusedColor: TColor;
…
published
property FocusedColor : TColor read FFocusedColor write FFocusedColor default clBtnFace;Code:constructor TsBitBtn.Create(AOwner: TComponent);
begin
…
FFocusedColor := clBtnFace;Code:procedure TsBitBtn.StdDrawItem(const DrawItemStruct: TDrawItemStruct);
…
if ThemeServices.ThemesEnabled then begin
…
else
…
if IsFocused or IsDefault then begin
Canvas.Pen.Color := clWindowFrame;
Canvas.Pen.Width := 1;
Canvas.Brush.Style := bsClear;
Canvas.Brush.Color := FocusedColor; // << THIS
Canvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
…
if IsDown then begin
Canvas.Pen.Color := clBtnShadow;
Canvas.Pen.Width := 1;
Canvas.Brush.Color := FocusedColor; //clBtnFace; << THIS CHANGED
Canvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
InflateRect(R, -1, -1);
end
else DrawFrameControl(DrawItemStruct.hDC, R, DFC_BUTTON, Flags);
…
if IsFocused and IsDefault then begin
Canvas.Pen.Color := clWindowFrame;
Canvas.Brush.Color := FocusedColor; //clBtnFace;
InflateRect(R, -2, -2); // << THIS
Canvas.Rectangle(R); // << THIS
R := ClientRect;
InflateRect(R, -4, -4);
DrawFocusRect(Canvas.Handle, R);
end;August 22, 2012 at 5:05 am #48805SupportKeymasterI'll try to add some code for a color changing in non-skinned mode.
But what about a programs with manifest? We can't change a button with standard Windows theme…
September 11, 2012 at 6:22 pm #48931SzakiLaciParticipantWhat do you mean by “programs with manifest” ?
The above code works perfectly under any kind of windows.
September 24, 2012 at 6:06 am #48971SupportKeymasterHello
Sorry for a delay
'SzakiLaci' wrote:What do you mean by “programs with manifest” ?
I mean this part of your code :
Code:if ThemeServices.ThemesEnabled then begin
…
elseYou skipped it, and button will not have a focused color if ThemesEnabled.
Or I'm wrong?
-
AuthorPosts
- You must be logged in to reply to this topic.