简体   繁体   English

无法访问tabpage1上tabpage2的日期时间选择器的文本或值

[英]Unable to access text or value of datetime picker of tabpage2 on tabpage1

I have windows form containing tab control, having two tab pages 我有包含选项卡控件的窗体,有两个标签页

在此输入图像描述

on form load event i passed value to datetimpicker1 exists on tab page 2 在表单加载事件上,我将值传递给datetimpicker1存在于标签页2上

private void Form1_Load(object sender, EventArgs e)
    {
      dateTimePicker1.Text = "2014-05-14 00:00:00.000";    
    }

and on check button click event i have following code 并在检查按钮单击事件我有以下代码

 private void button2_Click(object sender, EventArgs e)
    { 
        MessageBox.Show(dateTimePicker1.Value.ToString());
        MessageBox.Show(dateTimePicker1.Text.ToString());
    }

output: 输出:

在此输入图像描述

2)on navigating to tabpage2 & then click on check button 2)导航到tabpage2然后单击复选按钮

在此输入图像描述

output: 输出:

在此输入图像描述

& then after come back to tabpage1 & click on check it shows correct output 然后回到tabpage1并点击检查它显示正确的输出

在此输入图像描述

why it not showing at first time as we open form & clcik on check button without going to tab page 2 为什么它没有第一次显示,因为我们打开表格和clcik在检查按钮而不去标签页2

Your suggestions will be appreciated. 您的建议将不胜感激。

This is the quote from MSDN 这是MSDN的引用

Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown. 在显示选项卡页面之前,不会创建TabPage中包含的控件,并且在显示选项卡页面之前不会激活这些控件中的任何数据绑定。

You can, for example, programmatically switch to tabPage2 and back to the first tab. 例如,您可以通过编程方式切换到tabPage2并返回第一个选项卡。

Check out MSDN Reference : 查看MSDN参考

Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown. 在显示选项卡页面之前,不会创建TabPage中包含的控件,并且在显示选项卡页面之前不会激活这些控件中的任何数据绑定。

In form load you can select your tab as well. 在表单加载中,您也可以选择选项卡。

private void Form1_Load(object sender, EventArgs e)
    {
        tabControl1.SelectedTab = tabPage2;
        dateTimePicker1.Text = "2014-05-14 00:00:00.000";            
    }

Try this one 试试这个吧

   private void button2_Click(object sender, EventArgs e)
    { 
        MessageBox.Show(dateTimePicker1.Value.ToString());
        MessageBox.Show(dateTimePicker2.Value.ToString());
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM