Rod, I had done a little research for an article on .NET 2005's capabilities in development for smart devices and stuff. When I had started it, CF was in very bad shape. Microsoft has been doing a lot of promises and I really appreciate that the interfaces that Pocket PCs or CE or other smart devices support are much richer then those of palm and stuff but CF was very unstable and had a few classes that didnât make any sense in their depleted form. Microsoft has come a long way and their are a lot of improvements in CF regarding stability but some of the components are still left unfinished so to speak.
It was around that time that I had written a few small apps, I've modified my code to sort of create a sample code on which you may be able to base yours
Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Control AddButtons(String ID,Control after)
{
Button button2 = new System.Windows.Forms.Button();
button2.Location = new System.Drawing.Point(40, after.Location.Y + 30);
button2.Name = "Button" + ID.ToString();
button2.Size = new System.Drawing.Size(24, 39);
button2.TabIndex = 2;
button2.Text = "button2";
button2.Click += new System.EventHandler(PanelButton_Click);
panel1.Controls.Add(button2);
return (Control)button2;
}
private void button1_Click(object sender, EventArgs e)
{
Control temp = (Control)sender;
for (int i = 1; i < 10; i++)
{
temp = AddButtons(i.ToString(), temp);
}
}
private void PanelButton_Click(object sender, EventArgs e)
{
if(((Button)sender).Name == "Button1")
{
//STUFF
}
//MessageBox.Show(((Button)sender).Name);
}
Ya, I donât like being fed like this by code, myself, but i had this code so I'm giving it to you. The call to AddButtons can be moved to Form1_Load or some other suitable location, right now its at a button click.
Simpler way of generating such a code - just add the control you want to the form and format it the way you want. Go to InitializeComponent and copy the generated code from there, modify it to set the location and stuff properly and there you go. Good luck with your efforts.
Ankur