|
using System.IO;
using System.Reflection;
using System.Windows;
using System;
using FsControls;
namespace FsCalendarDemo
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadCalendars();
}
/// <summary>
/// Loads highlighted dates from a text file into a FsCalendar control.
/// </summary>
private void LoadCalendars()
{
// Get folder containing this app
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var n = path.LastIndexOf(@"\bin");
var appFolderPath = path.Remove(n);
var fileNames = new string[2];
fileNames[0] = String.Format(@"{0}\Holidays1.txt", appFolderPath);
fileNames[1] = String.Format(@"{0}\Holidays2.txt", appFolderPath);
var calendars = new FsCalendar[2];
calendars[0] = this.DemoCalendar1;
calendars[1] = this.DemoCalendar2;
for (var i = 0; i < 2; i++)
{
using (var reader = new StreamReader(fileNames[i]))
{
string line;
while ((line = reader.ReadLine()) != null)
{
// Parse line into data and tool tip
var s = line.Split(';');
var dateString = s[0];
var toolTip = s[1];
// Create DateTime object for date
var d = dateString.Split('/');
var date = new DateTime(DateTime.Now.Year, Convert.ToInt32(d[0]), Convert.ToInt32(d[1]));
// Add item to Calendar control's highlighted dates
calendars[i].HighlightedDates.Add(date, toolTip);
}
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.