Cannot transfer data between different Forms
Hello guys...
I am new to this forum and new to DotNet too..I am on C# track and currently facing the problem described below.I am practicing on VS2002 and 1.1 framework and my OS is windows XP.
As i am new to this forum, i dont know this query has been asked by anyone before..if yes then please send me the link to the page..ThankYou
Problem:
I am having two Forms in my application(Form1 and Form2).Form1 is startup form.Form1 contains a richtextbox and a button.This button opens Form2.Form2 contains a datetimepicker and a button.
Now what i want to do is, when i click the button of Form2, i want the richtextbox to show the date (datetimepicker.text). i dont know how to pass data from 1 form to another..please help me as soon as possible..
Thankyou;
Logically _Yours;
sudheer panwarPosted Jan 30, 2006, 6:43 AM
sol1. Create a data class wch contains a static property to hold the datepicker's value. Set the property in Form2 and get its value in Form1.
sol2.
create a public function in the Form1 wch accepts instance of Form2
public
void ShowDate(Form2 form2){richTextBox1.Text = form2.DATE;// Date is a public property in Form2 wch return datepicker's
Pass the parent form in the constructor of the Form2value
}
// in Form1
Form f = new Form2(this);
// In Form2
private
Form1 parentForm = null; public Form2(Form1 parent){InitializeComponent();
parentForm = parent;
}
From Form2 pass instance of Form2 in public function created in the Form1.
parentForm.ShowDate(
this);then u can access all the control/properties of Form2 in Form1.
confuse?