Color the selected region on a TPanel

Hello,

   I would like to divide the TPanel into say 24x18 blocks and once the user starts selecting these blocks I would like to fill them with the selected color, similar to masking. I am infact showing a video and would like to mask with the selected color on the video when the user selects the rectangular region.

with regards,
padmaja.
LVL 6
saravananvgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ziolkoCommented:
write Your own component based on TCustomPanel, where You can move Canvas property to public section, then use Canvas' to draw anything You want.

ziolko.
0
saravananvgAuthor Commented:
Hello Sir,

  I did find a solution for my question. I shall post it soon.

with regards,
padmaja.
0
saravananvgAuthor Commented:
Hello Sir,

  Here is the solution.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    Capturing : bool;
    Captured : bool;
    StartPlace : TPoint;
    EndPlace : TPoint;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
implementation

{$R *.DFM}

function MakeRect(Pt1 : TPoint;
                  Pt2 : TPoint) : TRect;
begin
  if pt1.x < pt2.x then begin
    Result.Left := pt1.x;
    Result.Right := pt2.x;
  end else begin
    Result.Left := pt2.x;
    Result.Right := pt1.x;
  end;
  if pt1.y < pt2.y then begin
    Result.Top := pt1.y;
    Result.Bottom := pt2.y;
  end else begin
    Result.Top := pt2.y;
    Result.Bottom := pt1.y;
  end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Captured then
  StartPlace.x := X;
  StartPlace.y := Y;
  EndPlace.x := X;
  EndPlace.y := Y;
  Capturing := true;
  Captured := true;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  S : TRect;
  tmpi,tmpj,tmpk1,tmpk2 : Integer;
begin
  if Capturing then
  begin
    EndPlace.x := X;
    EndPlace.y := Y;
    tmpk1:=4;
    tmpk2:=24;
    tmpi:=0;
    repeat
    tmpj:=0;
    repeat
      if PtInRect(rect(tmpj*Form1.Width div tmpk1,tmpi*Form1.Height div tmpk2,(tmpj+1)*Form1.Width div tmpk1,(tmpi+1)*Form1.Height div tmpk2),Point(EndPlace.X,EndPlace.Y)) then
      begin
        S.Left := tmpj*Form1.Width div tmpk1;
        S.Top := tmpi*Form1.Height div tmpk2;
        S.Right := (tmpj+1)*Form1.Width div tmpk1;
        S.Bottom := (tmpi+1)*Form1.Height div tmpk2;
        Form1.Canvas.Brush.Color := CLyELLOW;
        Form1.Canvas.FillRect(S);
      end;
    tmpj := tmpj+1;
    until tmpj>=tmpk1;
    tmpi := tmpi+1;
    until tmpi>=tmpk2;
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Capturing := false;
end;
end.

with regards,
padmaja.
0
GranModCommented:
Closed, 200 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.