Form1.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace Zadanie6
  10. {
  11. public partial class Form1 : Form
  12. {
  13. public Form1()
  14. {
  15. InitializeComponent();
  16. Person person = new Person { Name = "admin", Age = 18 };
  17. Label label1 = new Label();
  18. label1.Location = new Point(12, 10);
  19. label1.AutoSize = true;
  20. Controls.Add(label1);
  21. Label label2 = new Label();
  22. label2.Location = new Point(12, 40);
  23. label2.AutoSize = true;
  24. Controls.Add(label2);
  25. Button button = new Button();
  26. button.Location = new Point(12, 80);
  27. button.Text = "Change";
  28. button.AutoSize = true;
  29. Controls.Add(button);
  30. // изменяем свойство Name
  31. button.Click += (o, e) => person.Name = "admin";
  32. label1.DataBindings.Add(new Binding("Text", person, "Name", false, DataSourceUpdateMode.OnPropertyChanged));
  33. label2.DataBindings.Add(new Binding("Text", person, "Age", false, DataSourceUpdateMode.OnPropertyChanged));
  34. }
  35. private void Form1_Load(object sender, EventArgs e)
  36. {
  37. }
  38. public class Person
  39. {
  40. public string Name { get; set; } = "";
  41. public int Age { get; set; }
  42. }
  43. }
  44. }