Or do a component.invalidate + component.refresh
Main Topics
Browse All TopicsHi
I am using the default TColorProperty property editor so that users can choose the color they want from the list in my component. How do I tell the component to repaint itself in the chosen color? I have a Paint procedure but I need to know how to trigger it.
The property editor code is taken straight from the Delphi help. Here is what I have.
----
published
{ Published declarations }
property Color: TColor read FMyInplaceColor write FMyInplaceColor;
end;
function MyInplaceEdit.GetAttribute
begin
Result := [paDialog];
end;
procedure MyInplaceEdit.Edit;
var
ColorDialog: TColorDialog;
begin
ColorDialog := TColorDialog.Create(Applic
try
ColorDialog.Color := GetOrdValue; { use the existing value }
if ColorDialog.Execute then
begin { if the user OKs the dialog... }
SetOrdValue(ColorDialog.Co
end; { ...use the result to set value }
finally
ColorDialog.Free; { destroy the editor }
end;
end;
procedure TColorButton.Paint;
begin
inherited Paint;
With Canvas do
begin
Brush.Color := Color;
Brush.Style := bsSolid;
Rectangle(Left, Top, Left+Width, Top+Height);
end;
end;
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for the latest replies, but it's still not working. I have discovered that if i remove the line "inherited Paint" from the Paint procedure the button disappears from the form. On single-stepping through the code it definitely goes through the whole Paint procedure, so why will it not paint the button?
ON and TName: When I add InvalidateRect(TColorButto
LukA YJK: I have tried putting Paint in all the sections but it will not work.
Thanks ON and Luka YJKOK - here's the declaration:
type
MyInplaceEdit = class(TColorProperty)
public
procedure Edit;
function GetAttributes: TPropertyAttributes;
end ;
type
TColorButton = class(TSpeedButton)
private
{ Private declarations }
FMyInplaceColor: TColor;
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
published
{ Published declarations }
property Color: TColor read FMyInplaceColor write FMyInplaceColor;
end;
procedure Register;
implementation
//What happens if you change the Paint procedure like this:
procedure TColorButton.Paint;
var R:TRect;
begin
inherited Paint;
R:=ClientRect;
InflateRect(R,-1,-1);
with Canvas do begin
Brush.Color := FMyInplaceColor;
Brush.Style := bsSolid;
FillRect(R);
end;
end;
//P.S. And indeed, your button doesn't have a handle, as it descends via TSpeedButton from TGraphicControl (the non-windowed branch of the vcl)
Business Accounts
Answer for Membership
by: pcsentinelPosted on 2006-09-08 at 00:40:56ID: 17477559
If your code is right then you should just need a Component.Repaint;