code_junkie

Dynamic control in c#

Nov 13th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // something like this but I need to fill in each elements of the matrix...
  2. private void CreateSpecificControl(string requestedType)
  3. {
  4. if (requestedType == "CheckBox")
  5. {
  6.  
  7. CheckBox control1 = new CheckBox();
  8.  
  9. control1.Click += new EventHandler(chk_CheckedChanged);
  10.  
  11. //TableLayout panel
  12. layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
  13. layout.Controls.Add(control1);
  14.  
  15. }
  16. else
  17. {
  18. Label control1 = new Label();
  19.  
  20. control1.Text = "Not a checkbox";
  21. layout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
  22. layout.Controls.Add(control1);
  23.  
  24. }
  25.  
  26. }
  27.  
  28. myUserControl.Controls.Add(new CheckBox());
Add Comment
Please, Sign In to add comment