Jayanth Reddy

Jayanth Reddy

  • NA
  • 250
  • 9.8k

To check previous status of dynamic functionalities of form

Jul 9 2019 12:51 AM
Hi there,
 
I have created dynamic textboxes and according to my requirement textboxes should be saved permenantly on the form along with their properties even if we close and open the app again.Here is my code every thing was fine except retreiving the TextBox from backend after reopening the form.Can anyone help me.I am a beginner.
  1. namespace WindowsFormsApp1  
  2. {  
  3. public partial class Form1 : Form  
  4. {  
  5. public Form1()  
  6. {  
  7. InitializeComponent();  
  8. }  
  9. TextBox tb1;  
  10. TextBox tb2;  
  11. TextBox tb3;  
  12. TextBox tb4;  
  13. ComboBox cm;  
  14. int lbltext = 1;  
  15. int X = 1;  
  16. int A = 1;  
  17. private void Button1_Click(object sender, EventArgs e)  
  18. {  
  19. Show();  
  20. X++;  
  21. }  
  22. private new void Show()  
  23. {  
  24. if (X == 1)  
  25. {  
  26. tb1 = new TextBox();  
  27. tb1.Text = lbltext.ToString() + ".";  
  28. tb1.Height = 22;  
  29. tb1.Width = 17;  
  30. tb1.Left = 9;  
  31. tb1.Top = 140 + A * 36;  
  32. this.Controls.Add(tb1);  
  33. tb2 = new TextBox();  
  34. tb2.Height = 22;  
  35. tb2.Width = 60;  
  36. tb2.Left = 43;  
  37. tb2.Top = 140 + A * 36;  
  38. this.Controls.Add(tb2);  
  39. tb3 = new TextBox();  
  40. tb3.Height = 22;  
  41. tb3.Width = 64;  
  42. tb3.Left = 122;  
  43. tb3.Top = 140 + A * 36;  
  44. this.Controls.Add(tb3);  
  45. tb4 = new TextBox();  
  46. tb4.Height = 22;  
  47. tb4.Width = 80;  
  48. tb4.Left = 220;  
  49. tb4.Top = 140 + A * 36;  
  50. this.Controls.Add(tb4);  
  51. cm = new ComboBox();  
  52. cm.Text = "-NONE-";  
  53. cm.Items.Add("-PRESENT-");  
  54. cm.Items.Add("-LEAVE-");  
  55. cm.Items.Add("-HOLIDAY-");  
  56. cm.Left = 358;  
  57. cm.Width = 92;  
  58. cm.Height = 22;  
  59. cm.Top = 140 + A * 36;  
  60. Controls.Add(cm);  
  61. A += 1;  
  62. lbltext += 1;  
  63. }  
  64. else  
  65. {  
  66. MessageBox.Show("Cannot add more than one record at a time");  
  67. }  
  68. }  
  69. private void Button2_Click(object sender, EventArgs e)  
  70. {  
  71. ExampleDataContext dc = new ExampleDataContext();  
  72. TextBox4 tb = new TextBox4();  
  73. var duplicate = (from TextBox4 in dc.TextBox4s select tb.textvalue);  
  74. label1.Text = (duplicate.Count()).ToString();  
  75. if (duplicate.Count() == 0)  
  76. {  
  77. tb.textvalue = lbltext - 1;  
  78. tb.HeightValue = tb1.Height;  
  79. tb.WidthValue = tb1.Width;  
  80. tb.LeftValue = tb1.Left;  
  81. tb.TopValue = tb1.Top;  
  82. dc.TextBox4s.InsertOnSubmit(tb);  
  83. dc.SubmitChanges();  
  84. MessageBox.Show("Record inserted successfully");  
  85. }  
  86. else  
  87. {  
  88. MessageBox.Show("Record already exists");  
  89. }  
  90. }  
  91. private void Form1_Load(object sender, EventArgs e)  
  92. {  
  93. tb1 = new TextBox();  
  94. ExampleDataContext dc = new ExampleDataContext();  
  95. TextBox4 tb = new TextBox4();  
  96. var duplicate = (from TextBox4 in dc.TextBox4s where tb.textvalue==1 select tb.textvalue);  
  97. if(duplicate.Count()>0)  
  98. {  
  99. tb1.BorderStyle = BorderStyle.FixedSingle;  
  100. tb1.Text = tb.textvalue.ToString();  
  101. tb1.Top = tb.TopValue;  
  102. tb1.Height = tb.HeightValue;  
  103. tb1.Width = tb.WidthValue;  
  104. tb1.Left = tb.LeftValue;  
  105. this.Controls.Add(tb1);  
  106. }  
  107. }  
  108. private void Button3_Click(object sender, EventArgs e)  
  109. {  
  110. this.Close();  
  111. }  
  112. }  
  113. }  

Answers (2)