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
Date added: 15.03.2006
Hits: 14944

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

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

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

procedure TFormMain.Cross(X, Y: Integer);
  Image.Canvas.Pen.Color := clBlack;
  if RectSaved then
    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 := TBitmap.Create;
  BmpH.Width := Image.Width;
  BmpH.Height := 10;
  Image.Canvas,Rect(0, Y - 5, BmpH.Width, Y + 5));
  BmpV := TBitmap.Create;
  BmpV.Width := 10;
  BmpV.Height := Image.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) +')';

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:
If you want to advertise on the site use that e-mail:

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