Results 1 to 5 of 5

Thread: Control Arrays (Help me Pirate) [Resolved]

  1. #1

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166

    Control Arrays (Help me Pirate) [Resolved]

    Ok, I have this part down about creating controls and control arrays at run-time.

    Code:
    Button newbutton=new Button();
    newbutton.Location = new Point(200,100);
    newbutton.Size = new Size(100,150);
    this.Controls.Add(newbutton);
    My question is, how do I make new buttons (instances i guess) of a button I already have on my Window. For example, I like the size, the font, the color, I just want 8 more at run-time at different locations. How do I do that. I understand what you showed me last time with the labels, but I want to design the control on the window and then copy it at run-time. Hope this is detailed enough.
    Last edited by jordan23; Dec 30th, 2003 at 02:21 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This will clone any button passed to the void , This is the simplest way to do this . The more properties you set to the newly created buttons , the more they are similar to original button .

    Code:
    		}
    /// <summary>
    /// This will creates 8 Buttons . 
    /// </summary>
    /// <param name="Btn">The Button you want to clone</param>
    		void CreateButtons(Button Btn)
    		{
    			for (int i=0;i<8;i++)
    			{
    			Button b1=new Button();
    			b1.BackColor=Btn.BackColor;
    			b1.ForeColor=Btn.ForeColor;
    			b1.Font=Btn.Font;
    			b1.Text="Button"+i.ToString();
    			b1.Size=Btn.Size;
    			b1.Location= new Point(80,20*i);
    			b1.Name="Button" + i.ToString();
    			//Or use this to test it's cloning the same
    			//button you specified .
    			
    			//b1.Text=Btn.Text;
    			this.Controls.Add(b1);
    		}
    		
    		}
    
    
    Call it like this :
    
    CreateButtons(this.button1);

  3. #3

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Thanks Pirate, I have not been able to run it on my machine yet but it definitely makes sense. Do you have specific books you use or sites that you goto or are you just smart as hell???

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Come on , that's easy . But seriously , if you want to extend your knowledge , then let codeproject.com be your everyday habit .

  5. #5

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Thanks, I appreciate all your help. I will definitely visit it often.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width