Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7626391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:19:08+00:00 2026-05-31T05:19:08+00:00

When I try to disable a Button on a styled VCL from using the

  • 0

When I try to disable a Button on a styled VCL from using the follwing line of code

TButton(Sender).enabled:= False;

I get the this result (Button disabled at runtime)

enter image description here

instead of this!! (Button disabled at design time)

enter image description here

It’s really confusing to have two or more Buttons with the same color beside each other, one is disabled and the other is enabled

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:19:09+00:00Added an answer on May 31, 2026 at 5:19 am

    The cause of this issue is located in the Paint method of the TButtonStyleHook (in the Vcl.StdCtrls unit) style hook class.

    Locate this code in the method

    if FPressed then
      Details := StyleServices.GetElementDetails(tbPushButtonPressed)
    else if MouseInControl  then //this condition is triggered even if the button is disabled
      Details := StyleServices.GetElementDetails(tbPushButtonHot)
    else if Focused then //this condition is triggered even if the button is disabled
      Details := StyleServices.GetElementDetails(tbPushButtonDefaulted)
    else if Control.Enabled then
      Details := StyleServices.GetElementDetails(tbPushButtonNormal)
    else
      Details := StyleServices.GetElementDetails(tbPushButtonDisabled);
    

    And replace for this code

    if FPressed then
      Details := StyleServices.GetElementDetails(tbPushButtonPressed)
    else if MouseInControl and Control.Enabled then
      Details := StyleServices.GetElementDetails(tbPushButtonHot)
    else if Focused and Control.Enabled then
      Details := StyleServices.GetElementDetails(tbPushButtonDefaulted)
    else if Control.Enabled then
      Details := StyleServices.GetElementDetails(tbPushButtonNormal)
    else
      Details := StyleServices.GetElementDetails(tbPushButtonDisabled);
    

    Another option is rewrite the Style hook for the TButton :

    Check this code based in this article Fixing a VCL Style bug in the TButton component. The advantage of ths code is which you are fixing two issues 103708 and 103962.

    Uses
     Winapi.CommCtrl,
     Vcl.Themes,
     Vcl.Styles;
    
    type
      TCustomButtonH=class(TCustomButton);
    
      //we need this helper to access some strict private fields
      TButtonStyleHookHelper = class Helper for TButtonStyleHook
      protected
       function Pressed : Boolean;
       function DropDown: Boolean;
      end;
    
      //to avoid writting a lot of extra code we are to use TButtonStyleHook class and override the paint method
      TButtonStyleHookFix = class(TButtonStyleHook)
      protected
        procedure Paint(Canvas: TCanvas); override;
      end;
    
    
    { TButtonStyleHookFix }
    
    procedure TButtonStyleHookFix.Paint(Canvas: TCanvas);
    var
      LDetails          : TThemedElementDetails;
      DrawRect          : TRect;
      pbuttonImagelist  : BUTTON_IMAGELIST;
      IW, IH, IY        : Integer;
      LTextFormatFlags  : TTextFormatFlags;
      ThemeTextColor    : TColor;
      Buffer            : string;
      BufferLength      : Integer;
      SaveIndex         : Integer;
      X, Y, I           : Integer;
      BCaption          : String;
    begin
    
      if StyleServices.Available then
      begin
        BCaption := Text;
    
        if Pressed then
          LDetails := StyleServices.GetElementDetails(tbPushButtonPressed)
        else
        if MouseInControl and Control.Enabled then
          LDetails := StyleServices.GetElementDetails(tbPushButtonHot)
        else
        if Focused and Control.Enabled  then
          LDetails := StyleServices.GetElementDetails(tbPushButtonDefaulted)
        else
        if Control.Enabled then
          LDetails := StyleServices.GetElementDetails(tbPushButtonNormal)
        else
          LDetails := StyleServices.GetElementDetails(tbPushButtonDisabled);
    
        DrawRect := Control.ClientRect;
        StyleServices.DrawElement(Canvas.Handle, LDetails, DrawRect);
    
        if Button_GetImageList(handle, pbuttonImagelist) and (pbuttonImagelist.himl <> 0) and ImageList_GetIconSize(pbuttonImagelist.himl, IW, IH) then
        begin
          if (GetWindowLong(Handle, GWL_STYLE) and BS_COMMANDLINK) = BS_COMMANDLINK then
            IY := DrawRect.Top + 15
          else
            IY := DrawRect.Top + (DrawRect.Height - IH) div 2;
    
          //here the image is drawn properly according to the ImageAlignment value
          case TCustomButton(Control).ImageAlignment of
            iaLeft  :
                      begin
                        ImageList_Draw(pbuttonImagelist.himl, 0, Canvas.Handle, DrawRect.Left + 3, IY, ILD_NORMAL);
                        Inc(DrawRect.Left, IW + 3);
                      end;
            iaRight :
                      begin
                        ImageList_Draw(pbuttonImagelist.himl, 0, Canvas.Handle, DrawRect.Right - IW -3, IY, ILD_NORMAL);
                        Dec(DrawRect.Right, IW - 3);
                      end;
    
            iaCenter:
                      begin
                       ImageList_Draw(pbuttonImagelist.himl, 0, Canvas.Handle, (DrawRect.Right - IW) div 2, IY, ILD_NORMAL);
                      end;
    
    
            iaTop   :
                      begin
                       ImageList_Draw(pbuttonImagelist.himl, 0, Canvas.Handle, (DrawRect.Right - IW) div 2, 3, ILD_NORMAL);
                      end;
    
    
            iaBottom:
                      begin
                       ImageList_Draw(pbuttonImagelist.himl, 0, Canvas.Handle, (DrawRect.Right - IW) div 2, (DrawRect.Height - IH) - 3, ILD_NORMAL);
                      end;
    
          end;
    
    
        end;
    
        if (GetWindowLong(Handle, GWL_STYLE) and BS_COMMANDLINK) = BS_COMMANDLINK then
        begin
          if pbuttonImagelist.himl = 0 then
            Inc(DrawRect.Left, 35);
    
          Inc(DrawRect.Top, 15);
          Inc(DrawRect.Left, 5);
          Canvas.Font := TCustomButtonH(Control).Font;
          Canvas.Font.Style := [];
          Canvas.Font.Size := 12;
          LTextFormatFlags := TTextFormatFlags(DT_LEFT);
          if StyleServices.GetElementColor(LDetails, ecTextColor, ThemeTextColor) then
             Canvas.Font.Color := ThemeTextColor;
          StyleServices.DrawText(Canvas.Handle, LDetails, BCaption, DrawRect, LTextFormatFlags, Canvas.Font.Color);
          SetLength(Buffer, Button_GetNoteLength(Handle) + 1);
          if Length(Buffer) <> 0 then
          begin
            BufferLength := Length(Buffer);
            if Button_GetNote(Handle, PChar(Buffer), BufferLength) then
            begin
              LTextFormatFlags := TTextFormatFlags(DT_LEFT or DT_WORDBREAK);
              Inc(DrawRect.Top, Canvas.TextHeight('Wq') + 2);
              Canvas.Font.Size := 8;
              StyleServices.DrawText(Canvas.Handle, LDetails, Buffer, DrawRect,
                LTextFormatFlags, Canvas.Font.Color);
            end;
          end;
    
          if pbuttonImagelist.himl = 0 then
          begin
            if Pressed then
              LDetails := StyleServices.GetElementDetails(tbCommandLinkGlyphPressed)
            else if MouseInControl then
              LDetails := StyleServices.GetElementDetails(tbCommandLinkGlyphHot)
            else if Control.Enabled then
              LDetails := StyleServices.GetElementDetails(tbCommandLinkGlyphNormal)
            else
              LDetails := StyleServices.GetElementDetails(tbCommandLinkGlyphDisabled);
            DrawRect.Right := 35;
            DrawRect.Left := 3;
            DrawRect.Top := 10;
            DrawRect.Bottom := DrawRect.Top + 32;
            StyleServices.DrawElement(Canvas.Handle, LDetails, DrawRect);
          end;
    
        end
        else
        if (GetWindowLong(Handle, GWL_STYLE) and BS_SPLITBUTTON) = BS_SPLITBUTTON then
        begin
          Dec(DrawRect.Right, 15);
          DrawControlText(Canvas, LDetails, Text, DrawRect, DT_VCENTER or DT_CENTER);
          if DropDown then
          begin
            LDetails := StyleServices.GetElementDetails(tbPushButtonPressed);
            SaveIndex := SaveDC(Canvas.Handle);
            try
              IntersectClipRect(Canvas.Handle, Control.Width - 15, 0,
                Control.Width, Control.Height);
              DrawRect := Rect(Control.Width - 30, 0, Control.Width, Control.Height);
              StyleServices.DrawElement(Canvas.Handle, LDetails, DrawRect);
            finally
              RestoreDC(Canvas.Handle, SaveIndex);
            end;
          end;
    
          with Canvas do
          begin
            Pen.Color := StyleServices.GetSystemColor(clBtnShadow);
            MoveTo(Control.Width - 15, 3);
            LineTo(Control.Width - 15, Control.Height - 3);
            if Control.Enabled then
              Pen.Color := StyleServices.GetSystemColor(clBtnHighLight)
            else
              Pen.Color := Font.Color;
            MoveTo(Control.Width - 14, 3);
            LineTo(Control.Width - 14, Control.Height - 3);
            Pen.Color := Font.Color;
            X := Control.Width - 8;
            Y := Control.Height div 2 + 1;
            for i := 3 downto 0 do
            begin
              MoveTo(X - I, Y - I);
              LineTo(X + I + 1, Y - I);
            end;
          end;
    
        end
        else
        begin
          //finally the text is aligned and drawn depending of the value of the ImageAlignment property
          case TCustomButton(Control).ImageAlignment of
            iaLeft,
            iaRight,
            iaCenter : DrawControlText(Canvas, LDetails, BCaption, DrawRect, DT_VCENTER or DT_CENTER);
            iaBottom : DrawControlText(Canvas, LDetails, BCaption, DrawRect, DT_TOP or DT_CENTER);
            iaTop    : DrawControlText(Canvas, LDetails, BCaption, DrawRect, DT_BOTTOM or DT_CENTER);
          end;
        end;
      end;
    end;
    
    { TButtonStyleHookHelper }
    
    function TButtonStyleHookHelper.DropDown: Boolean;
    begin
      Result:=Self.FDropDown;
    end;
    
    function TButtonStyleHookHelper.Pressed: Boolean;
    begin
      Result:=Self.FPressed;
    end;
    
    
    initialization
     TStyleManager.Engine.RegisterStyleHook(TButton, TButtonStyleHookFix);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a very strange problem, i try to disable a toggle button for just
I get a run-time error NullPointerException whenever I try to click the options button
I disable a button with [myButton setEnabled: NO] . Then, I try to enable
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Try the following code public enum Color { Blue=1, Red=2, Green=3 } public List<Color>
Try as I might I cannot get my head around what the IteratorIterator class
Try as I might, I can't get a JNLP file to run locally (via
Try running this in a .VBS file MsgBox(545.14-544.94) You get a neat little answer
Disable a post back from asp.net i.e. buttons, links, gridview page index changing and
Using Prototype , the Form.Element.disable is said to be disabled the form as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.