Hi SePp,
The MonthCalendar form needs to know the date by receiving it in its
constructor or by exposing a public property the parent form can set before
displaying the MonthCalendar form. When the form closes, the parent can read
a property on the MonthCalendar form to find out which value the user
selected. Typically the code would like something like the below (will
probably need correction to work)
// Parent form
public void button1_Click(o bject sender, EventArgs e)
{
DateTime date = DateTime.Parse( label1.Text);
MonthCalendarFo rm mcFom = new MonthCalendarFo rm();
form.Date = date;
if(form.ShowDia log() == DialogResult.OK )
{
label1.Text = form.Date.ToStr ing();
}
}
// MonthCalendarFo rm
private DateTime _date
public DateTime Date
{
get{ return _date;}
set{ _date = value;}
}
protected override void OnLoad(EventArg s e)
{
monthCalendar1. Date = Date;
}
public void button1_Click(o bject sender, EventArgs e)
{
Date = monthCalendar1. Date;
DialogResult = DialogResult.OK ;
Close();
}
--
Happy Coding!
Morten Wennevik [C# MVP]
"SePp" wrote:
Hi there,
I have a WindowsForm which includes a label. I want to add a date to
this label which a user can select.
I thought it is probably the best to open another WindowsForm and to
add on this one a monthcalendar.
My prolbem is: How can I use this MonthcalendarFo rm to edit / add the
date of the label on other forms.
(It should be possible to use this monthcalendarfo rm for diffrent
forms)
Hope you can understand my problem!
Thank you very much in advance for your help.
Kind regards,
SePp