Form1.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace praktika6
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. TextBox textBox1 = new TextBox();
  18. textBox1.Location = new Point(12, 12);
  19. textBox1.Size = new Size(250, 27);
  20. Controls.Add(textBox1);
  21. Label label1 = new Label();
  22. label1.Location = new Point(12, 60);
  23. label1.AutoSize = true;
  24. Controls.Add(label1);
  25. label1.DataBindings.Add(new Binding("Text", textBox1, "Text"));
  26. textBox1.Location = new Point(12, 12);
  27. textBox1.Size = new Size(250, 27);
  28. Controls.Add(textBox1);
  29. label1.Location = new Point(12, 60);
  30. label1.AutoSize = true;
  31. Controls.Add(label1);
  32. Binding binding = new Binding("Text", textBox1, "Text");
  33. binding.Format += (sender, e) => e.Value = $"Content: {e.Value}";
  34. InitializeComponent();
  35. DateTimePicker dateTimePicker1 = new DateTimePicker();
  36. dateTimePicker1.Location = new Point(12, 12);
  37. dateTimePicker1.Size = new Size(250, 27);
  38. Controls.Add(dateTimePicker1);
  39. label1.Location = new Point(12, 60);
  40. label1.AutoSize = true;
  41. Controls.Add(label1);
  42. dateTimePicker1.Location = new Point(12, 12);
  43. dateTimePicker1.Size = new Size(250, 27);
  44. Controls.Add(dateTimePicker1);
  45. label1.Location = new Point(12, 60);
  46. label1.AutoSize = true;
  47. Controls.Add(label1);
  48. // создаем объект привязки
  49. // делаем доступным форматирование
  50. binding.FormattingEnabled = true;
  51. // строка форматирования
  52. binding.FormatString = "dd.MM.yyyy";
  53. }
  54. }
  55. }