C#将datetimepicker从winform移动到另一个winform

时间:2015-03-29 00:58:17

标签: c# sql winforms datetimepicker

我创建了一个使用数据集的程序,它生成3个报告, 它是从2 datetimepicker(句点的开始和结束)

设置的

但它们在FORM中,我用一个按钮分隔每个报告 所以每个报告都出现在不同的窗口中。 窗口加载,但我不知道如何通过datetimepickers,从第一个FORM到另外3个FORMS(每个窗口有不同的报告)

     public partial class GenerarIndicadores : Form
{
    unyrepDataSetTableAdapters.cargadatosTableAdapter ta_cargadatos;
    public GenerarIndicadores()
    {
        InitializeComponent();
        ta_cargadatos = new unyrepDataSetTableAdapters.cargadatosTableAdapter();
        int total = ta_cargadatos.GetData().Count;
        dateTimePicker1.MinDate = ta_cargadatos.GetData()[0].fechaInicio;
        dateTimePicker2.MinDate = ta_cargadatos.GetData()[0].fechaInicio;
        dateTimePicker1.MaxDate = ta_cargadatos.GetData()[total - 1].fechaTermino;
        dateTimePicker2.MaxDate = ta_cargadatos.GetData()[total - 1].fechaTermino;
    }

    public void button1_Click(object sender, EventArgs e)
    {
        new GenerarIndicadorGrupo().ShowDialog();
        this.aux_view5TableAdapter.FillTest(this.unyrepDataSet.aux_view5, dateTimePicker1.Value, dateTimePicker2.Value);

    }
    private void button2_Click(object sender, EventArgs e)
    {
        new GenerarIndicadorProveedor().ShowDialog();
        this.aux_view5TableAdapter.FillTest(this.unyrepDataSet.aux_view5, dateTimePicker1.Value, dateTimePicker2.Value);

    }

    private void button3_Click(object sender, EventArgs e)
    {
        new GenerarIndicadorObras().ShowDialog();
        this.aux_view5TableAdapter.FillTest(this.unyrepDataSet.aux_view5, dateTimePicker1.Value, dateTimePicker2.Value);

    }

我不知道如何将dateTimePickers传递给其他winforms,以便报告可以完美地获取信息。

1 个答案:

答案 0 :(得分:0)

将DateTimePicker的值存储在属性中,然后通过其他表单获取它。

Form1中:

    public string dTime{get;set;}
    dTime = datetimepicker1.Value.Date;

窗口2:

public string getDTime{get;set;}
getDtime = form1.dTime;
datetimepicker2.value.Date = getDtime;

P.S。 确保将form1初始化为其他表单以获取dTime的值。