1

I got 6 images like this in picture edit

image

but when I toggle the visibility of 2nd and 4th image it got empty or blank. What I want is the other image fill the empty or image like this (not just 2nd and 4th, visibility false whenever I want): image

the code I use is:

Bitmap gambr1 = new Bitmap(Properties.Resources.Add_f, 32, 32);      
Bitmap gambr2 = new Bitmap(Properties.Resources.Edit_f, 32, 32);       
Bitmap gambr3 = new Bitmap(Properties.Resources.Delete_f, 32, 32);        
Bitmap gambr4 = new Bitmap(Properties.Resources.print, 32, 32);      
Bitmap gambr5 = new Bitmap(Properties.Resources.sheet,32,32);        
Bitmap gambr6 = new Bitmap(Properties.Resources.close, 32, 32);        


private void dev12_Load(object sender, EventArgs e)
{
    pictureEdit1.Image = gambr1;
    pictureEdit2.Image = gambr2;
    pictureEdit3.Image = gambr3;
    pictureEdit4.Image = gambr4;
    pictureEdit5.Image = gambr5;
    pictureEdit6.Image = gambr6;

    if ( pictureEdit2.Visible == false)
    {                
        pictureEdit2.Visible = false; 
                       
    }
    if ( pictureEdit4.Visible == false)
    {
        pictureEdit4.Visible = false;          
    }
}

for each location is

Point a1 = new Point(162,10);
Point b1 = new Point(233,10);
Point c1 = new Point(304,10);
Point d1 = new Point(376,10);
Point e1 = new Point(447,10);
Point f1 = new Point(518,10);`
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • 3
    You can use a FlowLayuotPanel. – Reza Aghaei Aug 02 '16 at 10:42
  • @shad0wk yes, if i hide i want image is easy. but what if multiple it got so many if (condition) –  Aug 02 '16 at 10:45
  • Also as another option you can `Dock` all picture boxes to `Left` in a `Panel`. This way also when you make one of them invisible, others will fill the space to left. – Reza Aghaei Aug 02 '16 at 10:53

1 Answers1

1

You can use a FlowLayoutPanel. This way when a control is invisible, other control shifts and fill the space:

  • Set Padding of FlowLayoutPanel to specify the distance between the container and contents.
  • Set Margin of controls to specify the distance between controls in the FlowLayoutPanel.

In the below example, I set Padding of FlowLayoutPanel to 5 and Margin of all PictureBox controls to 5 and then set Visible of controls to false by click. You see as soon as I make a control invisible, the layout changes:

enter image description here

Also as another option you can Dock all picture boxes to Left in a Panel. This way also when you make one of them invisible, others will fill the space to left.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • thank for the suggestion. i will try to learn it. that picture is dock in bottom of form using panelcontrol1 should i switch it or just use it? –  Aug 02 '16 at 10:54
  • While `FlowLayoutPanel` is preferred, you can also `Dock` property of `PictureBox` controls to `Left` in the `Panel`. – Reza Aghaei Aug 02 '16 at 10:56
  • @RezaAghaei the thing is the picture box is at center of panelcontrol, if iam using dock left then theres no need for me to question this maybe - no offence –  Aug 02 '16 at 11:04
  • When I say the `PictureBox`, I mean the control which is showing an icon. So if it's a usercontrol created using a panel that have a picturebox in it, apply what I said on that control. – Reza Aghaei Aug 02 '16 at 11:06
  • my bad, i think it's still using my panelcontrol1. my panelcontrol dock on the bottom form and my `picturebox` still no dock. i learn first about flowlayoutpanel, thanks for the dock suggestion –  Aug 02 '16 at 11:13