保存代码:
string date = consumptionDateTimePicker.Text;
responseDialogResult = MessageBox.Show("确定要保存日记吗?","保存确认",MessageBoxButtons.YesNo,
MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
if(responseDialogResult == DialogResult.Yes)
{
//把日记内容写入二进制文件里
fileStreamObject = new FileStream(date + ".db",FileMode.CreateNew);
binaryWriterObject = new BinaryWriter(fileStreamObject);
//保存内容
binaryWriterObject.Write(RichText.Text);
fileStreamObject.Close();
binaryWriterObject.Close();
}
粗体我是这么想的。。。
string notename = "2006-12-12";
string year="", month="", day="";
int i = 0;
//把日期分开
for( ; notename[i]!= '-'; i++)
{
year+=notename[i].ToString();
}
i++;
for ( ; notename[i] != '-'; i++)
{
month += notename[i].ToString();
}
i++;
for ( ; i<notename.Length && notename[i] != '-' ; i++)
{
day += notename[i].ToString();
}
int iyear = int.Parse(year);
int imonth = int.Parse(month);
int iday = int.Parse(day);
DateTime myVacation3 = new DateTime(iyear, imonth, iday);
monthCalendar1.AddBoldedDate(myVacation3);
尝试过。。OK。没问题。