0

I have built an application using Windown Form in C#. The picture box original location is A.

In this application, I use button to move position of Picture box. When I press the button, this picture box will move to another position (Location B), but when I minimize application and restore it again, then the picture box return to its original position (Location A).

How can I fix this problem?

private void movePictureBox(int xPos, int yPos) {
  pBox8Button.BeginInvoke( new Action(() => {
    pBox8Button.Location = new Point(xPos, yPos);
  } ));
} 

I am using BeginInvoke, because I al running some thread.

The new position when I moved Picture box:

The new position when I moved Picture box

The position when I minimize and restore:

The position when I minimize and restore

XouDo
  • 945
  • 10
  • 19
  • You will need to post some code that demonstrates this. In my tests, the picture box did NOT return to the original location after the form was minimized then restored. Please post an [mre] to demonstrate what you describe. Otherwise we can only assume something else is going on. – JohnG Sep 13 '21 at 03:23
  • private void movePictureBox(int xPos, int yPos) { pBox8Button.BeginInvoke( new Action(() => { pBox8Button.Location = new Point(xPos, yPos); } )); } – Hoàng Anh Nguyen Sep 13 '21 at 03:53
  • It is unclear “why” the code uses the picture boxes `BeginInvoke` to create a new action for setting the picture boxes location… `pBox8Button.Location = new Point(xPos, yPos);` … would work without this. Unfortunately, even with the posted code, the picture box remains as expected after a minimize and restore of the form. Something else must be going on that you are not showing. – JohnG Sep 13 '21 at 06:19
  • My guess is you have another event handler (e.g. enter, focus, activated or shown) that repositions the picturebox, or possibly destroys it and recreates it in its original position. The picturebox doesn't just move itself. – John Wu Sep 13 '21 at 06:41
  • Yes I have another event handler, but in these event I don't call Change position Picture box function. I only Call That function when I click button – Hoàng Anh Nguyen Sep 13 '21 at 06:53
  • I suggest you [set a breakpoint when the property changes](https://stackoverflow.com/a/43765086/2791540) so you can see what line of code is making the change. – John Wu Sep 13 '21 at 06:55
  • I have set a breakpoint in change position function, but when I minimize and restore, my program don't go to this function – Hoàng Anh Nguyen Sep 13 '21 at 07:19

0 Answers0