Form1.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 WindowsFormsApp2
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. DateTimePicker dateTimePicker1 = new DateTimePicker();
  18. dateTimePicker1.Location = new Point(12, 12);
  19. dateTimePicker1.Size = new Size(250, 27);
  20. Controls.Add(dateTimePicker1);
  21. Label label1 = new Label();
  22. label1.Location = new Point(12, 60);
  23. label1.AutoSize = true;
  24. Controls.Add(label1);
  25. // создаем объект привязки
  26. Binding binding = new Binding("Text", dateTimePicker1, "Value");
  27. // делаем доступным форматирование
  28. binding.FormattingEnabled = true;
  29. // строка форматирования
  30. binding.FormatString = "dd.MM.yyyy";
  31. label1.DataBindings.Add(binding);
  32. }
  33. private void label1_Click(object sender, EventArgs e)
  34. {
  35. }
  36. private void button1_Click(object sender, EventArgs e)
  37. {
  38. Form2 new2 = new Form2();
  39. new2.Show();
  40. }
  41. }
  42. }