[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Color the selected region on a TPanel

Posted on 2006-04-06
5
Medium Priority
?
200 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:saravananvg
  • 2
4 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 16389719
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
 
LVL 6

Author Comment

by:saravananvg
ID: 16415204
Hello Sir,

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

with regards,
padmaja.
0
 
LVL 6

Author Comment

by:saravananvg
ID: 16434591
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
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16567799
Closed, 200 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question