Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can duplicate this groupbox in c#?
http://imageshack.us/photo/my-images/840/86124798.jpg/[^]
Posted
Comments
Kuthuparakkal 29-Aug-12 4:18am    
your question is not clear, NEED more info
Eren GENÇTÜRK 29-Aug-12 4:28am    
i want to create a lof of grupbox but ever grupbox like my first grupbox. they will be clone the other
Kuthuparakkal 29-Aug-12 4:37am    
select the groupbox and other controls(Draw selection recatangle or use Ctrl + Click each item) then copy it(Edit menu>Copy OR right click copy or Ctrl+C) and paste it how many time you want. Then arrangle them properly.
Eren GENÇTÜRK 29-Aug-12 4:41am    
The number of copies come from textbox so i must make with code.

1 solution

Something like that:

C#
int i = Convert.ToInt32(textbox1.Text);
while(i > 0)
{
   GroupBox mygroupbox = new GroupBox();

   foreach (Control ctrl in this.Controls)
   {
      if(ctrl is GroupBox)
      {
         GroupBox gbx = (GroupBox)ctrl;
         mygroupbox = gbx;
         break;
      }
   }
   this.Controls.Add(mygroupbox);
   i--;
}


Regards,
KZ
 
Share this answer
 
v3
Comments
Eren GENÇTÜRK 31-Aug-12 14:24pm    
Unable to cast object of type 'System.Windows.Forms.Button' to type 'System.Windows.Forms.GroupBox'.

this code made this problem.
Killzone DeathMan 10-Sep-12 9:49am    
Sorry, now its updated! :)
Eren GENÇTÜRK 11-Sep-12 10:21am    
thanks.

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