好吧,我有三种形式。在Form1
我有2dateTimePicker
和1按钮。当我单击该按钮时,我转到Form2
另一个按钮。当我单击该按钮时,它会显示一条消息,给出值dateTimePicker
。我在另一个Form3
地方有一个文本框。
问题:因此,与其在Form 2中的消息中不显示值,我想要的是,当我在Form1中的dateTimePicker中选择一个值并单击btn时,应打开Form2,而当我单击按钮form3时应在form2中打开,然后在Form3 dateTimePicker值中的文本框应显示。到目前为止,这就是我所拥有的。
private void button1_Click(object sender, EventArgs e) //form1
{
Form2 obj = new Form2(textBox1.Text,dateTimePicker1.Value,dateTimePicker2.Value);
this.Hide();
obj.ShowDialog();
this.Close();
Form3 f3 = new Form3(dateTimePicker1.Value);
}
string Name; //form2
DateTime DT1;
DateTime DT2;
DateTime DT3;
public Form2(string name, DateTime dt1,DateTime dt2)
{
InitializeComponent();
Name = name;
DT1 = dt1;
DT2 = dt2;
}
private void button2_Click(object sender, EventArgs e)
{
//MessageBox.Show("Check In Date: "+ DT1.ToString() + " Check Out Date: " + DT2.ToString());
Form3 f3 = new Form3(DT1);
f3.ShowDialog();
}
DateTime ChkInDate; // form3
public Form3(DateTime chkindate)
{
InitializeComponent();
ChkInDate = chkindate;
}
private void CheckInTxt_TextChanged(object sender, EventArgs e)
{
CheckInTxt.Text = ChkInDate.ToString();
}
您需要在Form3的构造函数中设置TextBox的初始值。
public Form3(DateTime chkindate)
{
InitializeComponent();
ChkInDate = chkindate;
CheckInTxt.Text = chkindate.ToString(); // add this line
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句