Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
- using System.Reflection;
- namespace Assignment2
- {
- public partial class Form2 : Form
- {
- public Form2() => InitializeComponent();
- private void Form2_Load(object sender, EventArgs e)
- {
- int y = 0;
- int dist = 100;
- int spaceBetween = 10;
- foreach (PropertyInfo Prop in Form1.UserSettings.GetType().GetProperties())
- {
- TextBox TB = new TextBox
- {
- Text = Prop.GetValue(Form1.UserSettings, null).ToString(),
- Location = new Point(dist, y),
- Width = 200,
- Tag = Prop.Name.ToLower()
- };
- TB.TextChanged += (object sender2, EventArgs e2) =>
- {
- ModifyCurrentSettings();
- (Owner as Form1).ApplySettings();
- };
- Controls.Add(TB);
- Label LBL = new Label
- {
- Text = Prop.Name,
- Location = new Point(0, y),
- Width = dist,
- Height = TB.Height,
- Tag = Prop.Name.ToLower(),
- TextAlign = ContentAlignment.MiddleCenter,
- AutoSize = false
- };
- Controls.Add(LBL);
- y += TB.Height + spaceBetween;
- }
- }
- private void Form2_FormClosing(object sender, FormClosingEventArgs e) => ModifyCurrentSettings();
- public void ModifyCurrentSettings()
- {
- Label[] lbls = Controls.OfType<Label>().ToArray();
- TextBox[] tbs = Controls.OfType<TextBox>().ToArray();
- for (int i = 0; i < tbs.Length; i++)
- Form1.UserSettings.GetType().GetProperty(lbls[i].Text).SetValue(Form1.UserSettings, tbs[i].Text == "" ? "1" : tbs[i].Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement