saravananvg
asked on
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.
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.
ASKER
Hello Sir,
I did find a solution for my question. I shall post it soon.
with regards,
padmaja.
I did find a solution for my question. I shall post it soon.
with regards,
padmaja.
ASKER
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(Sende r: 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(Sende r: 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.W idth div tmpk1,tmpi*Form1.Height div tmpk2,(tmpj+1)*Form1.Width div tmpk1,(tmpi+1)*Form1.Heigh t div tmpk2),Point(EndPlace.X,En dPlace.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.
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(Sende
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(Sende
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.W
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:
Shift: TShiftState; X, Y: Integer);
begin
Capturing := false;
end;
end.
with regards,
padmaja.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ziolko.