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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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
SteveBayCommented:
NOTE: Timage does not have a KeyDown Event handler. You will need to use the form's KeyDown event.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
voodoo22Author Commented:
Works great and thank you for the help much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.