How to color non-skinned BitBtn ?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #48760
    Hamilton
    Participant

      AFAIK 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

      #48761
      Hamilton
      Participant

        NB: For the panel make sure the SkinData.CustomColor flag is set to TRUE.

        #48772
        SzakiLaci
        Participant
          '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 clBtnFace

          But 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:

          #48773
          SzakiLaci
          Participant

            Temporarily 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;

            #48805
            Support
            Keymaster

              I'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…

              #48931
              SzakiLaci
              Participant

                What do you mean by “programs with manifest” ?

                The above code works perfectly under any kind of windows.

                #48971
                Support
                Keymaster

                  Hello

                  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

                  else

                  You skipped it, and button will not have a focused color if ThemesEnabled.

                  Or I'm wrong?

                Viewing 7 posts - 1 through 7 (of 7 total)
                • You must be logged in to reply to this topic.