(Yes, I know that we messed up our math tests at some point due to a problem with the coordinates!)
Problem
Point() always (x, y) coordinate. In your code:
private void Left_btn_Click(object sender, EventArgs e) { if (panel1.Location.X < 720) { panel1.Location = new Point(panel1.Location.Y , panel1.Location.X + +55); } } private void Right_btn_Click(object sender, EventArgs e) { if (panel1.Location.X < 720) { panel1.Location = new Point(panel1.Location.Y, panel1.Location.X -55); } }
You put an X coordinate with a Y value and vice versa.
Side note: there is a double + in the left mouse click event.
Step 1
First do the opposite:
private void Left_btn_Click(object sender, EventArgs e) { if (panel1.Location.X < 720) { panel1.Location = new Point(panel1.Location.X + 55 , panel1.Location.Y); } } private void Right_btn_Click(object sender, EventArgs e) { if (panel1.Location.X < 720) { panel1.Location = new Point(panel1.Location.X - 55, panel1.Location.Y); } }
Step 2
Secondly, look what you are looking for if you want. Note that moving to the left means that we decrease our X and move to the right, we increase X.
Should this not be done?
private void Left_btn_Click(object sender, EventArgs e) //The name is Left { if (panel1.Location.X < 720) { panel1.Location = new Point(panel1.Location.X - 55 , panel1.Location.Y); } } private void Right_btn_Click(object sender, EventArgs e) //The name is Right { if (panel1.Location.X < 720) { panel1.Location = new Point(panel1.Location.X + 55, panel1.Location.Y); } }
source share