How can I manipulate margins in C # dynamically?

0

I would like to know how to give margins to the pictureBox in C #, I currently have this code:

    posX = posX + 100;
    PictureBox pic = new PictureBox();
    pic.Location = new Point(posX, 50);
    pic.Name = "pic" + z;
    pic.Size = new Size(100, 100);
    pic.ImageLocation = directoriosE[z];
    pic.Margin = new Padding(100); --- deberia setear un valor al padding

In the last line I'm doing an equalization from margin to padding, but I did not find any function that was like this new Margin(100); and it was the only one that came closer, anyway it does not generate the setting of margins like me I was waiting.

Example of the current window.

As you can see, I would like to separate by means of margins each of my elements that is generated through a for cycle.

Also do it with the following code:

        Thickness margin = pic.Margin;
        margin.Left = 10;
        pic.Margin = margin;

But I got the following error:

  

Can not find the name or type of namespace   Thickness, missing a using directive or an assembly reference

I also did it in the following way:

 pic.Margin = new Padding(50,50,50,50);

But in the same way I do not apply the margin I am asking for. If I debug my application and position myself on my pic in the line where I set the maregenes, it gives me the following:

    
asked by David 05.04.2017 в 22:40
source

1 answer

1

Unfortunately in windows forms you must first get the width of the window and assign not with margin but with position x, and your element that is, your posX variable should be assigned posX = (posX + 100) +10; so that he has that margin the bad thing is that if you change the size of the screen you should do a Resize of the elements

    
answered by 06.04.2017 / 00:55
source