• 0

(c#2005)


Question

hi guys,

1- how i can add controls at a run time??

i wanna add labels depends on user entries number.

2- how i can create a table in c# at a run time?( table contains of labels which represents rows, columns and data entries) how i can store it depends on user entries( how i can determine how many labels).

i wanna it ordered depends on user entry, so i don't know how to determine (#of rows , #of columns and data entry).

i don't wanna use a gridview cause i don't make a datasource. so i think of labels.

i hope that u understand what i want.

hopefully of ur help.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

The thing to remember, is all the designer is doing is generating the code to create controls at runtime.

To create controls, you would initialise them like any other type instance, but remember to add them to the Container's control collection. The Container could be the Form control itself, or the Table control etc.

E.g.

TextBox myTextbox = new TextBox();
myTextBox.Text = "Test";
myTextBox.Left = 10;
myTextBox.Top = 10;
Form1.Controls.Add(myTextBox);

Have a look at the designer generated code (e.g. in Form1.designer.cs) to see how it generates this code.

Hope that points you down the right path :)

Link to comment
Share on other sites

  • 0
The thing to remember, is all the designer is doing is generating the code to create controls at runtime.

To create controls, you would initialise them like any other type instance, but remember to add them to the Container's control collection. The Container could be the Form control itself, or the Table control etc.

E.g.

TextBox myTextbox = new TextBox();
myTextBox.Text = "Test";
myTextBox.Left = 10;
myTextBox.Top = 10;
Form1.Controls.Add(myTextBox);

Have a look at the designer generated code (e.g. in Form1.designer.cs) to see how it generates this code.

Hope that points you down the right path :)

+1 (Y)

cant get any better..... :p

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.