Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 21, 2014 8:51 PM
Hi im new to this so...
I am trying to make a menu system and want to move a location picture box by an arrow key (Left arrow) only if it is in a certain location.
I was going to try and use an if statement which only works if ... and if .. = true but didnt know the code for location bit :L
I was wondering if anyone would help.
These locations need to be set coordinates and not movements, like move Picturebox 5 pxs.
Thank you :)
All replies (6)
Wednesday, January 22, 2014 11:44 AM âś…Answered
Hi
Override the Form's ProcessDialogKey method and put the logic inside that method
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Down)
{
// logic for DOWN arrow key event
if (pictureBox1.Location.X == 0 && pictureBox1.Location.Y == 0)
pictureBox1.Location = new Point(10, 10);
else if (pictureBox1.Location.X == 10 && pictureBox1.Location.Y == 10)
pictureBox1.Location = new Point(20, 20);
else if (pictureBox1.Location.X == 30 && pictureBox1.Location.Y == 30)
pictureBox1.Location = new Point(30, 30);
}
else if (keyData == Keys.Up)
{
// logic for UP arrow key event
}
else if (keyData == Keys.Left)
{
// logic for LEFT arrow key event
}
else if (keyData == Keys.Right)
{
// logic for RIGHT arrow key event
}
return base.ProcessDialogKey(keyData);
}
Wednesday, January 22, 2014 1:20 AM
Your code is going to be something along the lines of
if (myPictureBox.Left > someValue)
You'd use Left for the X direction and Top for the Y. There are also Right and Bottom properties too.
Wednesday, January 22, 2014 1:44 AM
kk that helps a little, but the part that im now stuck on is how do i make it so that it only moves if certain criteria are met (down key is pressed and picture box is at coordinates, e.g. 34, 183.
Only then will it move to its new coordinates,e.g 34, 340.
????
Wednesday, January 22, 2014 8:56 AM
Hi Matster2,
I found the similar question:
http://stackoverflow.com/questions/15112783/change-the-position-of-an-picturebox
http://stackoverflow.com/questions/5956207/key-press-events-in-c-sharp-moving-a-picturebox
By the way, I suggestion you post the question in the windows form forums at http://social.msdn.microsoft.com/Forums/en-US/home?category=windowsforms. It is appropriate and more experts will assist you.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Wednesday, January 22, 2014 11:11 AM
Do you have more dependencies for instance it should not rain.
If you are a programmer you must know a computer does not attempt to know what you mean.
That is in fact the same in this forum. We don't see your face, we don't hear your intonation, we don't know anything about you or your problem; the only thing we have like a computer is your written message.
So the first given reply to you is 100% correct, the others are only confusing.
Success
Cor
Wednesday, January 22, 2014 1:07 PM
Thank you so much this helped so much, i change it a little but without this code i wouldnt have been able to do it.
Thanks Again
Matster2 :)