Link to home
Start Free TrialLog in
Avatar of jbas
jbas

asked on

why drawfocusrect can'nt work to image?

hi.
  experts!i have some question in drawfocusrect,when a timage have assigned a picture these code can'nt work.
help!thanks!
       
unit Unitdrawfocusrect;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    MyPoint:TPoint;
    FDrawing:boolean;
    MyDrawRect:TRect;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  FDrawing:=true;
  MyDrawRect.Left:=X;
  MyDrawRect.Top:=Y;
  MyDrawRect.BottomRight:=MyDrawRect.TopLeft;
  MyPoint:=point(X,Y);
  drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
// image1.picture.bitmap.Canvas.DrawFocusRect(MyDrawRect);

end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   FDrawing:=false;
   drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
// image1.picture.bitmap.Canvas.DrawFocusRect(MyDrawRect);

end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   if  FDrawing=true then
   begin
// image1.picture.bitmap.Canvas.DrawFocusRect(MyDrawRect);

    drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawRect);
        if X>MyPoint.X then
        begin
            MyDrawRect.Left:=MyPoint.X;
            MyDrawRect.Right:=X;
        end
             else
        begin
            MyDrawRect.Left:=X;
            MyDrawRect.Right:=MyPoint.X
        end;
        if Y>MyPoint.Y then
        begin
           MyDrawRect.Top:=MyPoint.Y;
           MyDrawRect.Bottom:=Y;
        end
             else
        begin
           MyDrawRect.Top:=Y;
           MyDrawRect.Bottom:=MyPoint.Y
        end;
        Drawfocusrect(image1.Picture.Bitmap.Canvas.Handle,MyDrawrect);
// image1.picture.bitmap.Canvas.DrawFocusRect(MyDrawRect);

    end;
end;
end.
 
Avatar of Fraction
Fraction

Why can't you use the TCanvas.DrawFocusRect as disabled in your example?
Avatar of jbas

ASKER

thanks,
       use tcanvas.drawfocusrect or drawfocusrect(tcanvas.handle,r) all can'nt work well while a image assigned a picture.
     i want to zoom out/in the region focused,but that code can'nt work.so i need help.
  thanks.
ASKER CERTIFIED SOLUTION
Avatar of DrDelphi
DrDelphi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbas

ASKER

thanks.
you method can work well,later i will give you the points if the region can zoom in/out(can you help me too?:))
Try something like this:

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Bmp: TBitmap;
begin
  FDrawing:=false;
  drawfocusrect(self.canvas.handle, MyDrawRect);
  Bmp := TBitmap.Create;
  Bmp.Width := MyDrawRect.Right-MyDrawRect.Left;
  Bmp.Height := MyDrawRect.Bottom-MyDrawRect.Top;
  Bmp.Canvas.CopyRect(Rect(0, 0, Bmp.Width, Bmp.Height),image1.Picture.Bitmap.Canvas, MyDrawRect);
  image1.Picture.Bitmap.Canvas.StretchDraw(Rect(0, 0, image1.Width, image1.Height), Bmp);
  Bmp.Free;
end;
Avatar of jbas

ASKER

thanks to Fraction and DrDelphi !
to Fraction :
please talk the points in here.
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20306972