Solved

Simple TCheckBox Question

Posted on 2002-03-25
5
318 Views
Last Modified: 2010-04-04
Hi

I'm looking to find a way of changing the background colour on the 'checked' part of the TCheckBox, from it's default white.

Does anyone know how either to add this additional property to the component or better still a 3rd party component already available.

Thanks in advance.

Palin
0
Comment
Question by:palin2000
5 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6895201
Hi Palin,

I'm fairly sure there is no way to change the component itself, but you maybe able to create your own TCheckbox derived from TCustomCheckbox.

I'm sure there are HEAPS of checkbox components around which allow you to do this.  The one I use (which isn't DB aware) is called TBitCheckBox.  It ships with two different sets of state bitmaps (checked, unchecked, greyed, disabled) but you can specify your own (just whip them up in MS Paint or something similar).

If you'd like a copy, email me at gtho1971@hotmail.com and I'll email you a copy of it.

Stu
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 50 total points
ID: 6897073
Below ive done a quick example on how to draw on to the CheckBox control by creating a TCheckbox decendent and overriding the paint handler. You may beable to adapt it to draw your required box peice:

type
  TNewCheckBox = class(TCheckBox)
  private
    procedure WMPaint(var Message : TWMPaint); message WM_PAINT;
  end;

var
  ChkBox : TNewCheckBox;

...

procedure TNewCheckBox.WMPaint(var Message : TWMPaint);
var
  PS : PaintStruct;
begin
  with Message do begin
    DC := BeginPaint(Self.Handle, PS);
    DrawText(DC, 'Test Text', -1, PS.rcPaint, DT_VCENTER or DT_SINGLELINE);
  end;
  EndPaint(Self.Handle, PS);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ChkBox := TNewCheckBox.Create(Self);
  with ChkBox do
  begin
    Parent := Form1;
    Caption := 'Test';
    Width := 100;
    Height := 20;
    Left := 10;
    Top := 10;
  end;
end;

I'm not sure if it works because I currently can't test it but it should do.

Cheers,

Alan
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6897707
Nice, Alan, very nice!
0
 

Expert Comment

by:CleanupPing
ID: 9343222
palin2000:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 7

Expert Comment

by:knightmad
ID: 9471004
Wow, Its been a long time since this comment have been visited!

palin2000,
No comment has been added lately (19 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to alanwhincup http:#6897073

-- Please DO NOT accept this comment as an answer ! --

Thanks,

knightmad
EE Cleanup Volunteer

Remember you (all) can object this recommendation if you disagree, just leave a post here explaining why are you objecting and what should be done instead.
Within 7 days probably this thread will be closed, so, hurry up! : )
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

16 Experts available now in Live!

Get 1:1 Help Now