传递一个日期值从一个Windows操作系统在C#中的另一种形式 [英] Passing a Date Value from one Windows From to Another Form in C#

查看:201
本文介绍了传递一个日期值从一个Windows操作系统在C#中的另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个非常复杂的项目,我非常非常新的Windows项目结果
我有2种形式:

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


  • ViewSchedule.cs

  • Scheduler.cs (它是一种对话形式)

  • ViewSchedule.cs
  • Scheduler.cs (it is a Dialog Form)

ViewSchedule.cs 有两个日期是从日历中选择。两个日期被选中。结果它们被保存在RESP:

ViewSchedule.cs has two dates to be selected from the Calendar. Two dates are selected.
They are saved in Resp:

_fromDate = dtFromDate.DateTime.ToUniversalTime();
_toDate = dtToDate.DateTime.ToUniversalTime();



表格2即 Scheduler.cs 是一个dialogForm。在这里,在 ViewScheduler 选定的日期应该出现在这里。

Form 2 ie Scheduler.cs is a dialogForm. Here the dates selected in ViewScheduler should appear here.

我需要帮助。

推荐答案

您需要在对话框的形式创建的公共属性和显示对话框之前设置这些属性。

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

然后的onLoad使用这些属性值

Then onLoad use these property values.

在窗口2添加这些日期属性:

In form2 add these date properties:

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

    public Form2()
    {
        InitializeComponent();
    }
}

和从Form1中访问这些如下:

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();
}

这篇关于传递一个日期值从一个Windows操作系统在C#中的另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆