Guest User

Untitled

a guest
Jan 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. private void GenerateControls(string formType)
  2. {
  3. string[] formParameters = engine.GetFormParameters(formType);
  4. if (formParameters == null) return;
  5. SplitterPanel panel = splitContainer.Panel1;
  6. panel.Controls.Clear();
  7. List<Pair<Label, TextBox>> controlPairs = new List<Pair<Label, TextBox>>();
  8. int tabIndex = 0;
  9. Point labelPoint = panel.Location + new Size(20, 20);
  10. Size initialOffset = new Size(0, 30);
  11. Size horizontalOffset = new Size(40, 0);
  12. Size tBoxSize = new Size(40,20);
  13. foreach (string parameter in formParameters)
  14. {
  15. Label label = new Label
  16. {
  17. Text = parameter,
  18. Tag = "Parameter Label",
  19. Name = $"lbl{parameter}",
  20. Location = (labelPoint += initialOffset)
  21. };
  22. TextBox textBox = new TextBox
  23. {
  24. AcceptsTab = true,
  25. TabIndex = tabIndex++,
  26. Text = "",
  27. Tag = parameter,
  28. Name = $"txt{parameter}",
  29. MaximumSize = tBoxSize,
  30. MinimumSize = tBoxSize,
  31. Size = tBoxSize,
  32. Location = labelPoint + horizontalOffset
  33. };
  34. controlPairs.Add(new Pair<Label, TextBox>(label, textBox));
  35. }
  36.  
  37. foreach (Pair<Label, TextBox> pair in controlPairs)
  38. {
  39. panel.Controls.Add(pair.First);
  40. panel.Controls.Add(pair.Second);
  41. }
  42. }
  43.  
  44. private void GenerateControls(string formType)
  45. {
  46. string[] formParameters = engine.GetFormParameters(formType);
  47. if (formParameters == null) return;
  48. SplitterPanel panel = splitContainer.Panel1;
  49. panel.Controls.Clear();
  50. int tabIndex = 0;
  51. Point labelPoint = panel.Location + new Size(20, 20);
  52. Size verticalOffset = new Size(0, 30);
  53. Size tBoxSize = new Size(200,20);
  54. int maxLabelLength = 0;
  55. foreach (string parameter in formParameters)
  56. {
  57. Label label = new Label
  58. {
  59. Text = parameter,
  60. Tag = "Parameter Label",
  61. Name = $"lbl{parameter}",
  62. Location = (labelPoint += verticalOffset),
  63. AutoSize = true
  64. };
  65. panel.Controls.Add(label);
  66. if (label.Size.Width > maxLabelLength)
  67. {
  68. maxLabelLength = label.Size.Width;
  69. }
  70. }
  71. Size horizontalOffset = new Size(maxLabelLength + 30, 0);
  72. labelPoint = panel.Location + new Size(20, 20) + horizontalOffset;
  73. foreach (string parameter in formParameters)
  74. {
  75. TextBox textBox = new TextBox
  76. {
  77. AcceptsTab = true,
  78. TabIndex = tabIndex++,
  79. Text = "",
  80. Tag = parameter,
  81. Name = $"txt{parameter}",
  82. MaximumSize = tBoxSize,
  83. MinimumSize = tBoxSize,
  84. Size = tBoxSize,
  85. Location = labelPoint += verticalOffset
  86. };
  87. panel.Controls.Add(textBox);
  88. }
  89.  
  90. }
Add Comment
Please, Sign In to add comment