Solved

Read Only Checkbox

Posted on 2004-04-21
9
295 Views
Last Modified: 2010-05-18
Hi all.

Hopefully this is an easy question..

I am writing an application that displays the status of true false attributes of an account using check boxes on a form.

I do not want the users to be able to uncheck - re-check the check boxes, but do not want the checkboxes to appear disabled as they tend to blend in with the form and look crappy.. (Technical term).

Is there a way to make the check boxes read only, or is there another check box component I can use for this??
0
Comment
Question by:BedouinDN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 125 total points
ID: 10883516
Will need to derive a new component and handle the Mouse events yoruself:

type
  TReadOnlyCheckBox = class(TCheckBox)
  private
    fReadOnly: Boolean;
  protected
    procedure WmLButtonDown(var Msg: TWMLButtonDown);
        message Wm_LButtonDown;
    procedure WmLButtonUp(var Msg: TWMLButtonUp);
        message Wm_LButtonUp;
    procedure WmLButtonDblClk(var Msg: TWMLButtonDblClk);
        message Wm_LButtonDblClk;
  published
    property ReadOnly: Boolean read fReadOnly write fReadOnly;
  end;

...

procedure TReadOnlyCheckBox.WmLButtonDown(var Msg: TWMLButtonDown);
begin
  if not ReadOnly then
    inherited
  else
    Msg.Result := 0;
end;

procedure TReadOnlyCheckBox.WmLButtonUp(var Msg: TWMLButtonUp);
begin
  if not ReadOnly then
    inherited
  else
    Msg.Result := 0;
end;

procedure TReadOnlyCheckBox.WmLButtonDblClk(var Msg:
TWMLButtonDblClk);
begin
  if not ReadOnly then
    inherited
  else
    Msg.Result := 0;
end;



Shane
0
 

Expert Comment

by:steveaish
ID: 10883524
Not the tidiest way but have a private variable called Check1Checked type boolean

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    procedure FormCreate(Sender: TObject);
  private
    Check1Checked : Boolean;

when you make your checkbox checked or unchecked also set this variable (Check1Checked := Checkbox1.Checked)

in the OnClick event of the Checkbox

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if Checkbox1.Checked <> Check1Checked then
  begin
    Checkbox1.Checked := Check1Checked;
  end;
end;

0
 
LVL 17

Expert Comment

by:mokule
ID: 10883616

My solution to every problem is TPanel :)

Place CheckBoxes on a TPanel and set

Panel1.Enabled := False;

That's all
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:BedouinDN
ID: 10883696
Have accepted Shanes answer as I will be using this a lot and so will create a new derived Checkbox, Mokule - Your answer works beautifully and I will use yours for now until I get the time to create. Please look for "Points for Mokule" in the list for the same amount of points..

Steveaish, I have tried to do this but ended up in an endless loop until stack overflow - Seems setting the checked value calls the OnCLick method.. :-(

Thanks again guys..

Colin.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10883698
Why You don't like TPanel :(
0
 
LVL 4

Author Comment

by:BedouinDN
ID: 10883703
Beat ya..
:-)
0
 
LVL 17

Expert Comment

by:mokule
ID: 10883711
Ooops. And yet You like it also. Thanks :))
I was too fast.
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10883807
I like Mokule solution as well, i may use that in the future for speediency.... <SMILE>

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10883904
Wow :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question