?
Solved

why drawfocusrect can'nt work to image?

Posted on 2002-06-01
6
Medium Priority
?
590 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 400 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
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!

 

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

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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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