Passing a Date Value from one Windows From to Another Form in C#

前端 未结 4 1056
轮回少年
轮回少年 2021-01-16 16:33

I am working on a very complex project and I am very very new to the windows Project.
I have 2 Forms :

  • ViewSchedule.cs
  • Sch
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 17:06

    You need to create public properties in the dialog form and set these properties before showing the dialog.

    Then onLoad use these property values.

    In form2 add these date properties:

    public partial class Form2 : Form
    {
        public DateTime Date1 { get; set; }
        public DateTime Date2 { get; set; }
    
        public Form2()
        {
            InitializeComponent();
        }
    }
    

    And from form1 access these as follows:

    private void Form1_Load(object sender, EventArgs e)
    {
       Form2 frm2 = new Form2();
       frm2.Date1 = DateTime.Now;
       frm2.Date2 = DateTime.Now;
       frm2.ShowDialog();
    }
    

提交回复
热议问题