panning an image with the directional keys

Hello,

I did a quick search on EE the other day and found this topic http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20652266.html  in which kretzschmar posted the answer to and while it does do the job nicely when using the mouse it does not cover using the directional keys to pan the image so I was wanting to know if anyone knew how I might extend that code to include this functionality.

Cheers
voodoo22Asked:
Who is Participating?
 
SteveBayConnect With a Mentor Commented:
NOTE: Timage does not have a KeyDown Event handler. You will need to use the form's KeyDown event.
0
 
mikelittlewoodCommented:
Well since the XX and YY are global variables, write an event onKeyDown for the image component and check which key ( left, right, up, down) was pressed and increment/decrement these values.
Then in an onKeyUp event, adjust the position of the image (top and left) against the XX and YY values.
0
 
voodoo22Author Commented:
thanks for the reply but would you mind posting a little bit of code for just one of the key events. I should be able to figure the rest of them out once I have seen how one of them is formatted.

Cheers,
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
voodoo22Author Commented:
Still looking for an answer to this so anyone else want to help then please do and I have upped the points for this question to 200 as I really need a working example asap.
0
 
mikelittlewoodCommented:
Hi sorry Voodoo, just been a bit too busy at work at the moment.
If I get chance once I get home I will take a look at it for you.
In the mean time if someone else gives you a working example then great.
0
 
SteveBayCommented:
Voodoo,

Add this event handler to the form you found in http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20652266.html 

You can control the speed by changing the value of PIXELS_PER


procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
const PIXELS_PER = 10;
begin
	if key = VK_UP then
		if Image1.Top + Image1.Height - Panel1.ClientHeight > 0 then
			Image1.Top := Image1.Top - PIXELS_PER;
 
	if key = VK_DOWN then
		if Image1.Top < 0 then
			Image1.Top := Image1.Top  + PIXELS_PER;
 
	if key = VK_LEFT then
		if Image1.Left + Image1.Width - Panel1.ClientWidth > 0 then
			Image1.Left := Image1.Left - PIXELS_PER;
 
	if key = VK_RIGHT then
		if Image1.Left < 0 then
			Image1.Left := Image1.Left + PIXELS_PER;
	ReFitImage;
end;

Open in new window

0
 
voodoo22Author Commented:
Works great and thank you for the help much appreciated.
0
All Courses

From novice to tech pro — start learning today.