문제

Hi How can I save 2 last winform state? I use it when user clicks on "cancel" button. I wanna to set the form state into its proper one.

Thank you

도움이 되었습니까?

해결책

You can save values of all relevant controls to the application configuration file, for example in FormClosing event (you'd need to create the properties yourself)

Properties.Settings.Default.textA = textBoxA.Text;

and restore them on form onLoad event

textBoxA.Text = Properties.Settings.Default.textA;

다른 팁

Create a new instance of the form each time you need it.

  • On Form1_Load you set the data.
  • On btnSave_Click you save the data and close the form.
  • On btnCancel_Click you close the form.

If you can't create an instance of the form every time you could consider using a user control that you instanciate instead.

Part from that if you are using WPF you could bind GUI directly to datastructure.
In WinForms you can bind directly to some controls such as Grid/PropertyList/etc.
You can use Reflection to automaticaly iterate through the forms controls, but that is a bit complex.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top