How to automatically save and automatically load all properties in c # winforms?

How to automatically save all winforms properties at close and automatically load all winforms properties at boot? WITH#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace SControl
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Controls.Count; i++)
            {
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(Controls[i]));
                Stream stream = File.Open("test.xml", FileMode.Create);
                x.Serialize(stream, Controls[i]);
            }
        }
    }
}
+3
source share
4 answers

Your question is a bit unclear, but

If you need to save / load the Layout of the form , see

Windows Forms Custom Settings in C #

If you need to save / load an object / class , look

Load and save objects in XML using serialization

EDIT:

This will show you how to save certain settings for the form properties.

.NET- XML

- XML -

, .

, -

  • , , / .
  • ? ? XML ?
  • , , / . / (Button, TextBox, Gridview, ListView)
  • , . , , , ( ) , . .
  • xml ( xml). , , , .
+6

- , Form, .

, , .

Form.Load Form.Closing. Form.Closing , . Form.Load, , , , .

0

, .

, Windows Forms.

:

//save the winform position and size upon closing
private void Form1_FormClosed(
   object sender, FormClosedEventArgs e)
{
    Properties.Settings.Default.FormPosition = this.Location;
    Properties.Settings.Default.FormSize = this.Size;
    Properties.Settings.Default.Save();
}

//load the winform position and size upon loading
private void Form1_Load(object sender, EventArgs e)
{
    this.Size = Properties.Settings.Default.FormSize;
    this.Location = Properties.Settings.Default.FormPosition;
}

:

0

, , , , . , , WinForm. // Windows Forms Control, , .

0

Source: https://habr.com/ru/post/1728710/


All Articles