Doron Muzar
Doron Muzar

Reputation: 443

How do I find the corrent location of the pictureBox? It should be to be in the center of form1

In Form1 I have this code:

pb = new PictureBox();
pb.Location = new Point(this.Bounds.Width / 2,
                        this.Bounds.Height / 2);
pb.Size = new Size(500,500);

The form1 size is: 800x600

If I'm using this code then pb(pictureBox) will be at the center of the form and to the right bottom. I mean the 0,0 of the pb is in the center of the form . I need that the pb 0,0 will be some where that all the pb will be over the center area of the form1.

In this case the pb 0,0 is in the center of the form so I see the rest of the pb to the right and bottom.

Upvotes: 0

Views: 97

Answers (1)

King King
King King

Reputation: 63317

This is what you want:

pb.Size = new Size(500,500);
pb.Location = new Point((ClientSize.Width-pb.Width)/2,
                        (ClientSize.Height-pb.Height)/2);

Upvotes: 2

Related Questions