troubleshooting Question

Trigger to paint a component after color change

Avatar of APS NZ
APS NZFlag for New Zealand asked on
Delphi
17 Comments1 Solution416 ViewsLast Modified:
Hi

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.GetAttributes: TPropertyAttributes;
begin
     Result := [paDialog];
end;

procedure MyInplaceEdit.Edit;
var
  ColorDialog: TColorDialog;
begin
  ColorDialog := TColorDialog.Create(Application);                { construct the editor }
  try
    ColorDialog.Color := GetOrdValue;                           { use the existing value }
    if ColorDialog.Execute then
    begin                             { if the user OKs the dialog... }
      SetOrdValue(ColorDialog.Color);
    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;
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros