Delphi Source Code
Search engine
HOME Components Tutorials Add Trick Links Contacts
ActiveX Components Database Files Forms Graphic Internet/Lan Math Miscellaneous Multimedia Printing Strings System Information Windows

Delphi source code for Graphic >> Move a cross in canvas to show X/Y values


Category: Graphic
Title: Move a cross in canvas to show X/Y values
Author: swissdelphicenter.ch
Date added: 15.03.2006
Hits: 13879


private
   BmpH, BmpV : TBitmap;
   OldX, OldY: Integer;
end;
var
  RectSaved : boolean = false;

procedure TFormMain.FormCreate(Sender: TObject);
begin
  PanelImage.DoubleBuffered := true; // This prevents that the image is blinking
  LabelHint.Transparent := true;
  LabelHint.Font.Color := clNave;
end;

procedure TFormMain.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Cross(X, Y);
end;

procedure TFormMain.Cross(X, Y: Integer);
begin
  Image.Canvas.Pen.Color := clBlack;
  if RectSaved then
  begin
    Image.Canvas.CopyRect(Rect(OldX - 5, 0, OldX + 5, BmpV.Height),
    BmpV.Canvas, Rect(0,0,BmpV.Width,BmpV.Height));
    Image.Canvas.CopyRect(Rect(0, OldY - 5, BmpH.Width, OldY + 5),
    BmpH.Canvas, Rect(0,0,BmpH.Width,BmpH.Height));
    BmpH.Free;
    BmpV.Free;
  end;
  BmpH := TBitmap.Create;
  BmpH.Width := Image.Width;
  BmpH.Height := 10;
  BmpH.Canvas.CopyRect(Rect(0,0,BmpH.Width,BmpH.Height),
  Image.Canvas,Rect(0, Y - 5, BmpH.Width, Y + 5));
  BmpV := TBitmap.Create;
  BmpV.Width := 10;
  BmpV.Height := Image.Height;
  BmpV.Canvas.CopyRect(Rect(0,0,BmpV.Width,BmpV.Height),
                 Image.Canvas,Rect(X - 5, 0, X + 5, BmpV.Height));
  Image.Canvas.MoveTo(0, Y);
  Image.Canvas.LineTo(Image.Width, Y);
  Image.Canvas.MoveTo(X, 0);
  Image.Canvas.LineTo(X, Image.Height);
  RectSaved := true;
  OldX := X;
  OldY := Y;
  LabelHint.Left := X + 36;
  LabelHint.Top := Y - 15;
  LabelHint.Caption := '(X:' + IntToStr(X) + ' x Y:' + IntToStr(Y) +')';
end;


Related Delphi Source Code:
Delphi Tricks
Delphi Tricks
For any problems or recommendations about Delphi Tricks site, please

feel free to contact us on that e-mail: support@delphitricks.com.
If you want to advertise on the site use that e-mail: advertise@delphitricks.com.

You can freely use or modify these Delphi source codes for non-commercial use. We are not responsible of any damages that can be caused by the utilisation of that source codes.

Copyright © 2006-2010 AVSoftware Company. All rights reserved.
Hide IP tricks