Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends
sorry for poor english.
1-this is my question: i have a user control like below.
<img src="http://upload.tehran98.com/img1/bv67egrfbg661ti1goo5_thumb.jpg" border="0" alt="bv67egrfbg661ti1goo5.jpg" />
http://upload.tehran98.com/img1/bv67egrfbg661ti1goo5.jpg

there is some textbox-combox-lable-button and so on.
2-i have a form like this that threre is a add button and panel control into it.
i want to add the same user control in form when i click add button like below.

<img src="http://upload.tehran98.com/img1/hip0ihejx3zdobo2f1zi_thumb.jpg" border="0" alt="hip0ihejx3zdobo2f1zi.jpg" />
and like this.
---------------------------------------------------------------------------------
<img src="http://upload.tehran98.com/img1/98szs4wgijzook4v9v_thumb.jpg" border="0" alt="98szs4wgijzook4v9v.jpg" />
------------------------------------------------------------------------------------
and when i click again -add a another usercontrol righte under that one.
and so on.
i want that when i click add button another user control add to uppermost of them.
i want that when i click on close button a usercontrol in middle of form that be hidden and
other user conrols shift to up and be ordered like this.

<img src="http://upload.tehran98.com/img1/rzqknaj346vctjzvyo_thumb.jpg" border="0" alt="rzqknaj346vctjzvyo.jpg" />
http://upload.tehran98.com/img1/rzqknaj346vctjzvyo.jpg

how can i do that .
pls help me.
Posted

1 solution

Use FLowLayOutPanel. Add controls into this panel.
You an get automatic scroll options and many other functionality.
Be sure to read the Msdn section of the panel.
 
Share this answer
 
Comments
mahmoodof 15-Apr-13 6:41am    
hello - ok . i need a flow layout but i have problem with that.
when i want to add a new control to flowlayout it is not added.
this is my code:


private Button btnAdd = new Button();


private void button1_Click(object sender, EventArgs e)
{
flowLayoutPanel1.Controls.Add(btnAdd);



}

private void Form2_Load(object sender, EventArgs e)
{
//Set up the form.
this.MaximizeBox = false;
this.MinimizeBox = false;
this.BackColor = Color.White;
this.ForeColor = Color.Black;
this.Size = new System.Drawing.Size(632, 375);
this.Text = "Run-time Controls";
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterScreen;
//*****************************************
this.btnAdd.BackColor = Color.Gray;
this.btnAdd.Text = "Add";
this.btnAdd.Location = new System.Drawing.Point(90, 25);
this.btnAdd.Size = new System.Drawing.Size(50, 25);
}
how can i add a new control to flowflowlayout ?
johannesnestler 15-Apr-13 8:58am    
You are adding a reference to the existing button control. Create a new one on button1_Click and it will be added. (This behaviour is because you may add an existing control to another Controls collection - every control only belongs to one Controls collection...). I also think FlowLayoutPanel is a good advice for you, but of course you can control the layout youself by setting Anchor, Dock, Size, Location properties or overriding Resize on the Container (maybe best in a Special Container control doing all the layout of the child controls)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900