Center controls within a maximized form

2

I would like to put cinco controles picturebo x aligned just in the top middle of the screen. (The length of the screen is different for each user).

To begin with, my idea is that the window is maximizada , to obtain the total size of form . (The form will be transparente , with its property backcolor ), hence you need to place the 5 imagenes right in the medio superior of the screen.

My idea was that once I got the measure in pixeles totales , I would divide it in two, and challenge half the length of the first control.

So, if the longitud is 1000 , and the imagen is 50x50 , you would have to put it from 1000/2 -25 = 475 .

The image would be located between the pixel 475 and the 525 . Perfectly aligned.

This is the code:

int tamañoimg = Invocador1.Size.Height; 
int centro = this.Height / 2 - ( tamañoimg / 2 );
Invocador1.Left = centro;

But the position is not exactly half, but roughly 1/4 to the right.

Reading, I have heard that it could be that when the form is loaded, it still does not get the number of real pixels when maximizing the window.

How could I solve it?

    
asked by Omar 15.08.2018 в 00:01
source

2 answers

3

You are using height measurements, to be able to place them horizontally ...

You should use the Width property that measures the width.

int tamañoimg = Invocador1.Size.Width; 
int centro = this.Width/ 2 - ( tamañoimg / 2 );
Invocador1.Left = centro;
    
answered by 15.08.2018 / 00:59
source
2

Have you tried with some control ?, like the TableLayoutPanel and from there based on adding the picturebox you need.

Greetings.

    
answered by 15.08.2018 в 00:51