Solved

Read Only Checkbox

Posted on 2004-04-21
9
284 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
  • 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now