Search code examples
c#winformsrecords

What is the best approach for the purpose to save the value of the variables and to get them passed between the WinForms?


I am currently working on a C# project in which I got a couple of WinForms (currently 5 windows).

From these windows, I need to save all the information that has been filled(all the text from textBoxes, comboBoxes, dataGridViews, checkBoxes). In each window, there is control containing data I will need later to generate a script.

So my question is: What is the best approach for the purpose to save the value of the variables and to get them passed between the WinForms?

For now, I am storing the data from the controls in variables, but I believe there is much better and efficient way of doing this. (And also the variables are passing between the screens. So basically if I have in screen1 variable A, I need to access it from screen2 where there is another variable B, screen 3 needs A and B and variable C appears there, and so on ....)

I've been thinking about:

  1. Saving the data in a text file(which I would like to NOT do it.)
  2. User Settings (but I am pretty sure I cannot store the data from the grid in it. If I am mistaken I will appreciate letting me know!)
  3. And the last one I mentioned I am using - passing variables between the WinForms.

Solution

  • You can create dto-class for each window, put data from window's control to corresponding dto and then serialize it.