Solved

why drawfocusrect can'nt work to image?

Posted on 2002-06-01
6
579 Views
Last Modified: 2010-04-04
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.
 
0
Comment
Question by:jbas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Fraction
ID: 7049004
Why can't you use the TCanvas.DrawFocusRect as disabled in your example?
0
 

Author Comment

by:jbas
ID: 7049138
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.
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 100 total points
ID: 7049195
Draw the focus rectangle on the form's canvas instead. For example:


var rec:Trect;
begin
 rec:=Rect(0,0,100,100);
 drawfocusrect(image1.canvas.handle,rec); ///does NOT work
end;

//---------------------------------------------------
var rec:Trect;
begin
 rec:=Rect(image1.left,image1.top,100,100);
 drawfocusrect(self.canvas.handle,rec);//WORKS a charm!
end;


Good luck!!






0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jbas
ID: 7049238
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?:))
0
 
LVL 1

Expert Comment

by:Fraction
ID: 7049363
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;
0
 

Author Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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