delphidelphi-xe4

How to set `ElevationRequired` for `TBitBtn`


I need to mark a TBitBtn (not TButton), that the button action requires elevation. I set ElevationRequired to True, but I do not get the shield icon.

To reproduce, place a TButton and a TBitBtn on a form:

procedure TForm1.FormCreate(Sender: TObject);
begin
    Button1.ElevationRequired := True;
    BitBtn1.ElevationRequired := True;
end;

Button1 is displayed with shield icon, BitBtn1 is not.


Solution

  • This is not possible.

    A VCL TBitBtn is an owner-drawn Win32 BUTTON control. You can see that here:

    procedure TBitBtn.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      with Params do Style := Style or BS_OWNERDRAW;
    end;
    

    Hence, a TBitBtn is not drawn by Windows but manually by the Pascal code in Vcl.Buttons.pas. Specifically, TBitBtn.DrawItem(const DrawItemStruct: TDrawItemStruct) does the painting.

    And here you can see that there is no mentioning of ElevationRequired.

    Hence, TBitBtn doesn't support this.

    In general, don't use TBitBtn; use TButton to get the native Win32 button.