Programming/C#

[C#] Properties.Setting 값 설정하기.

BadaGreen_Kim 2019. 1. 15. 15:38
  • Window Example Form
 

 

 
  • Settings.settings 설정

 

 

 

 

 

        • Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace UserSettingDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        private void Form1_Load(object sender, EventArgs e)
        {
            Text = Properties.Settings.Default.Title;
            chkRememberPassword.Checked = Properties.Settings.Default.CheckBox;
            lblValue.Text = Properties.Settings.Default.Label; 
            txtValue.Text = Properties.Settings.Default.TextBox;   
            this.Location = new Point(Properties.Settings.Default.PX, Properties.Settings.Default.PY); 
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Properties.Settings.Default.CheckBox = chkRememberPassword.Checked;
            Properties.Settings.Default.Title = txtTitleForm.Text;
            Properties.Settings.Default.Label = txtValue.Text;
            Properties.Settings.Default.TextBox = txtValue.Text;
            Properties.Settings.Default.PX = this.Location.X;
            Properties.Settings.Default.PY = this.Location.Y;
            Properties.Settings.Default.Save();
        }
 
        private void btnSetTitleForm_Click(object sender, EventArgs e)
        {
            this.Text = txtTitleForm.Text;
        }
 
        private void btnSetValueLabel_Click(object sender, EventArgs e)
        {
            lblValue.Text = txtValue.Text;
        }
    }
 
}
cs