windowsdelphithemesreadonlytcheckbox

How to display a "greyed-out" read-only checkbox using Delphi under windows themes


I want read-only check boxes to be greyed out, but display their checked/unchecked status under Windows (XP and above), but I'm having some issues.

NOTE - Regarding 'read-only': It appears that Delphi's TCheckBox, doesn't even have a read-only option, this has been 'faked' by placing it on a TPanel and disabling that... However the question still remains valid, how does one achieve a read-only check-box that is greyed out, OR a inactive check-box that displays it's state.

Disabled checkboxes are greyed out, but these don't display a checked or unchecked state. Read-only check boxes can, but when Windows themes them, they just look like normal editable check boxes. The read-only box cannot have its value changed, but it looks like it can.

In XP with themes turned off (i.e. under classic mode), it works correctly.

Solutions that aren't acceptable, due to how clumsy/unprofessional they are for a large app or the development time/cash ratio of it, include these: - Manually greying the text and displaying an image of the checkbox status. - Disabling themes on the check-boxes, as the look without them is ugly. - Using custom checkboxes

Screenshots of the issue - These are three checked check boxes, one disabled, one read only and one normal:

enter image description here enter image description here

Although the read-only and editable check boxes appear different, that's just because the editable box in the first image has the focus. The read-only one will look the same if it's the one with the focus, as see in the second image.


Solution

  • Anonymous has asked for code that demonstrates disabled check boxes showing their checked state.

    program Project28;
    
    uses
      Forms, StdCtrls;
    
    var
      Form: TForm;
    
    procedure Initialise;
    var
      cb1, cb2: TCheckBox;
    begin
      cb1 := TCheckBox.Create(Form);
      cb2 := TCheckBox.Create(Form);
      cb1.Parent := Form;
      cb2.Parent := Form;
      cb1.Top := 0;
      cb2.Top := 16;
      cb1.Enabled := False;
      cb2.Enabled := False;
      cb1.Checked := False;
      cb2.Checked := True;
      cb1.Caption := 'Checkbox1';
      cb2.Caption := 'Checkbox2';
    end;
    
    begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TForm, Form);
      Initialise;
      Application.Run;
    end.
    

    enter image description here