2

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Anonymous
  • 31
  • 1
  • 4
  • 2
    If by *inactive* you mean *disabled*, I cannot duplicate your issue on XP, disabled check boxes show their check states. And I cannot find a *read-only* property of the control.. – Sertac Akyuz Mar 09 '11 at 02:49
  • Sorry, yes you're correct. By active and inactive I mean enabled and disabled. – Anonymous Mar 09 '11 at 03:04
  • Further investigation reveals this isn't even as I thought. Delphi's TCheckBox, as you said doesn't even have a read-only option, this has been faked by placing it on a TPanel and disabling that... I'll have to sort that out with Dev before I can progress further on the correct functioning of checkboxes. – Anonymous Mar 09 '11 at 03:14
  • 2
    Ok. Better delete the question before you have a downvote. ;) – Sertac Akyuz Mar 09 '11 at 03:25
  • 1
    I don't understand why this isn't a valid question @David. It asks how to get a disabled check box that still displays its checked state. Although there was misunderstanding about how to achieve a *read-only* check box, that's not actually important to the question. – Rob Kennedy Mar 09 '11 at 16:13
  • @Rob A disabled check-box does display its checked status. – David Heffernan Mar 09 '11 at 16:18
  • @David, not according to the screen shots. – Rob Kennedy Mar 09 '11 at 17:01
  • 1
    @Rob I've no idea where those screenshots come from, but I've been using disabled vanilla check boxes, with checked state displayed, all the way back to Delphi 1! – David Heffernan Mar 09 '11 at 17:02
  • @Sertac - Thanks for the help, you've uncovered an issue that will most definitely help in the resolution of my question. I however do not care about a downvote or a loss in reputation, cheers for the heads-up. @David, Thanks for the downvote, you need not comment it on the post however. You say disabled check-boxes display state for you, could you give me example code of this, as mine do not. Either that or as stated, do you having theming on, in which case you would not see this issue. @Rob, Cheers for the support, haha :) – Anonymous Mar 09 '11 at 20:14
  • @Anonymous I've rescinded my down-vote. It seems you do have a problem. You problem though is not how to get a disabled check box to display its state. Your problem is to work out what it is in your code that it stopping them doing so! – David Heffernan Mar 09 '11 at 20:32

2 Answers2

1

Checkboxes with themes show the checked mark when disabled, as you can see in this screenshot:

enter image description here

The dfm used to create this looks like this:

object Form2: TForm2
  Left = 0
  Top = 0
  Caption = 'Form2'
  ClientHeight = 337
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object CheckBox1: TCheckBox
    Left = 8
    Top = 8
    Width = 153
    Height = 17
    Caption = 'Disabled an checked'
    Checked = True
    Enabled = False
    State = cbChecked
    TabOrder = 0
  end
  object CheckBox2: TCheckBox
    Left = 8
    Top = 31
    Width = 153
    Height = 17
    Caption = 'Enabled and checked'
    Checked = True
    State = cbChecked
    TabOrder = 1
  end
  object CheckBox3: TCheckBox
    Left = 8
    Top = 54
    Width = 153
    Height = 17
    Caption = 'Disabled an un-checked'
    Enabled = False
    TabOrder = 2
  end
  object CheckBox4: TCheckBox
    Left = 8
    Top = 77
    Width = 153
    Height = 17
    Caption = 'Enabled and un-checked'
    TabOrder = 3
  end
end
jachguate
  • 16,976
  • 3
  • 57
  • 98
0

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

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • "Your problem is to work out what it is in your code that it stopping them doing so!" Right you are, and I intend to do so :) Cheers! – Anonymous Mar 09 '11 at 21:26