Solved

why drawfocusrect can'nt work to image?

Posted on 2002-06-01
6
562 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
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

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

Author Comment

by:jbas
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:jbas
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now