First off I'd like to mention I'm a student taking C# this semester. The instructor I have has not been helpfull in teaching the language I feel, and I leave the class more confused than when I entered. She gave us an assignment that requires us to make a calendar that performs calculations with dates counting days to and past Valentines day which is then displayed in a richTextBox as the appropriate sentence depending on what date is selected within the monthCalendar. I am having problems with figuring out how to do the calculations and then displaying the number from the calculations within the sentence. I welcome any help and thank you in advance. The code i have from the .cs file is as follows:
using
System;using System.Collections.Generic;
using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Linq;using
System.Text;using
System.Windows.Forms;namespace
WindowsFormsApplication1{
public partial class Form1 : Form{
public Form1(){
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e){
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e){
if (e.Start.CompareTo(new DateTime(2009, 2, 14)) == 0){
richTextBox1.Text =
"Happy Valentines day";}
else if (e.Start.CompareTo(new DateTime(2009, 2, 14)) <= 0){
richTextBox1.Text =
"Its #ofdays until Valentines Day";}
else{
richTextBox1.Text =
"Its been #ofDays since Valentines Day";}
}
}
}
Jan MontanoPosted Jan 25, 2009, 11:44 PM
private void monthCalendar1_ValueChanged(object sender, EventArgs e)
{
DateTime valentinesDay = new DateTime(2009,2,14);
DateTime selectedDate = monthCalendar1.Value.Date;
TimeSpan timespan = valentinesDay.Subtract(selectedDate);
if (timespan.Days < 0)
{
richTextBox1.Text = string.Format("{0} days since valentine's day", Math.Abs(timespan.Days));
}
else if (timespan.Days > 0)
{
richTextBox1.Text = string.Format("{0} days till valentine's day", timespan.Days);
}
else
{
richTextBox1.Text = string.Format("Happy Valentines Day");
}
}