[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

why drawfocusrect can'nt work to image?

Posted on 2002-06-01
6
Medium Priority
?
604 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 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