Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance with Pen Position on Bitmap Canvas

Status
Not open for further replies.

LEICJDN1

Technical User
Nov 27, 2002
201
GB
Hi,

Am attempting to log a file of coordinates with each mouse click. Have bitmap loaded as Image1. OnMouseMove works fine and displays constant coordinates as mouse moves over image.
However, cannot seem to get OnMouseClick event to work correctly. Need it do log the X and Y at the position of the click into two variables which will be save and also displayed on the screen.

Any help appreciated.

Thanks
 
Use the OnMouseDown event of the TImage, becuase it supplies you with the x and y coordinates relative to the top-left of the image
Code:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Showmessage('X: ' + inttostr(X) + ' Y: ' + inttostr(Y));
end; Clive [infinity]
 
Forgot to offer some file writing code!
Code:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  CursorPositionFile: TextFile;
begin
  Showmessage('X: ' + inttostr(X) + ' Y: ' + inttostr(Y));
  Assign(CursorPositionFile, C:\temp\CursorPos.txt)
  Rewrite(CursorPositionFile);
  Writeln(CursorPositionFile, 'X=' + IntToStr(X) + ' Y=' + IntToStr(Y));
  CloseFile(CursorPositionFile);
end;
Clive [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top