|
-
Dec 30th, 2003, 09:34 AM
#1
Thread Starter
Addicted Member
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.
-
Dec 30th, 2003, 11:06 AM
#2
Sleep mode
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);
-
Dec 30th, 2003, 01:18 PM
#3
Thread Starter
Addicted Member
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???
-
Dec 30th, 2003, 02:09 PM
#4
Sleep mode
Come on , that's easy . But seriously , if you want to extend your knowledge , then let codeproject.com be your everyday habit .
-
Dec 30th, 2003, 02:20 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|