ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Color Randomizer
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

848 Posts

Posted - Apr 14 2021 :  18:18:21  Show Profile  Reply
Here I show how to transform the TIEColorButton into a "Color Randomizer":

type
  TMyIEColorButton = class(TIEColorButton)
    protected
      procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  end;
  TIEColorButton = class(TMyIEColorButton);

implementation

procedure TMyIEColorButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Form1.IEColorButton1.SelectedColor := RGB(Random(256), Random(256), Random(256)); 
end;


This saves the user a lot of work: Namely, to manually select a color in the color picker. He just has to click the button until he gets a color that he likes! ;-)

xequte

38107 Posts

Posted - Apr 15 2021 :  05:57:31  Show Profile  Reply
Hi Peter

You can also use this method in hyieutils.pas

function IERandomColor(PastelSet: Boolean = False): TColor;

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

848 Posts

Posted - Apr 15 2021 :  06:13:20  Show Profile  Reply
Hi Nigel,

thanks for the hint. So the code would be:

type
  TMyIEColorButton = class(TIEColorButton)
    protected
      procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  end;
  TIEColorButton = class(TMyIEColorButton);

implementation

procedure TMyIEColorButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Tag = 999 then // restrict randomness to a specific IEColorButton
    SelectedColor := hyieutils.IERandomColor 
  else
    inherited;
end;


Is this correct?
Go to Top of Page

xequte

38107 Posts

Posted - Apr 16 2021 :  18:25:49  Show Profile  Reply
Hi Peter

That is correct. Though you should also handle key presses by overriding KeyUp in the same way.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: