Replaced custom calendar control. Fixed bolded dates issue.

This commit is contained in:
gamosoft_cp 2013-04-26 15:32:14 +00:00
parent 1221c65f35
commit ebde96e76d
7 changed files with 791 additions and 124 deletions

View File

@ -31,24 +31,24 @@
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.numRangeDays = new System.Windows.Forms.NumericUpDown(); this.numRangeDays = new System.Windows.Forms.NumericUpDown();
this.lblRangeDays = new System.Windows.Forms.Label(); this.lblRangeDays = new System.Windows.Forms.Label();
this.apptCalendar = new Outlook2013TodoAddIn.DoubleClickMonthCalendar();
this.ctxMenuAppointments = new System.Windows.Forms.ContextMenuStrip(this.components); this.ctxMenuAppointments = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuItemReplyAllEmail = new System.Windows.Forms.ToolStripMenuItem(); this.mnuItemReplyAllEmail = new System.Windows.Forms.ToolStripMenuItem();
this.hdrDate = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.hdrSubject = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.listView1 = new System.Windows.Forms.ListView();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnRefresh = new System.Windows.Forms.Button(); this.btnRefresh = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.grpRefresh = new System.Windows.Forms.GroupBox();
this.apptCalendar = new Outlook2013TodoAddIn.CustomCalendar();
((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).BeginInit();
this.ctxMenuAppointments.SuspendLayout(); this.ctxMenuAppointments.SuspendLayout();
this.groupBox1.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.grpRefresh.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// numRangeDays // numRangeDays
// //
this.numRangeDays.Location = new System.Drawing.Point(60, 21); this.numRangeDays.Location = new System.Drawing.Point(53, 28);
this.numRangeDays.Maximum = new decimal(new int[] { this.numRangeDays.Maximum = new decimal(new int[] {
15, 15,
0, 0,
@ -60,7 +60,7 @@
0, 0,
0}); 0});
this.numRangeDays.Name = "numRangeDays"; this.numRangeDays.Name = "numRangeDays";
this.numRangeDays.Size = new System.Drawing.Size(55, 22); this.numRangeDays.Size = new System.Drawing.Size(48, 25);
this.numRangeDays.TabIndex = 2; this.numRangeDays.TabIndex = 2;
this.numRangeDays.Value = new decimal(new int[] { this.numRangeDays.Value = new decimal(new int[] {
3, 3,
@ -72,23 +72,12 @@
// lblRangeDays // lblRangeDays
// //
this.lblRangeDays.AutoSize = true; this.lblRangeDays.AutoSize = true;
this.lblRangeDays.Location = new System.Drawing.Point(10, 23); this.lblRangeDays.Location = new System.Drawing.Point(10, 30);
this.lblRangeDays.Name = "lblRangeDays"; this.lblRangeDays.Name = "lblRangeDays";
this.lblRangeDays.Size = new System.Drawing.Size(44, 17); this.lblRangeDays.Size = new System.Drawing.Size(42, 19);
this.lblRangeDays.TabIndex = 3; this.lblRangeDays.TabIndex = 3;
this.lblRangeDays.Text = "Days:"; this.lblRangeDays.Text = "Days:";
// //
// apptCalendar
//
this.apptCalendar.Dock = System.Windows.Forms.DockStyle.Top;
this.apptCalendar.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.apptCalendar.Location = new System.Drawing.Point(0, 0);
this.apptCalendar.MaxSelectionCount = 1;
this.apptCalendar.Name = "apptCalendar";
this.apptCalendar.TabIndex = 4;
this.apptCalendar.DoubleClickEx += new System.EventHandler(this.apptCalendar_DoubleClickEx);
this.apptCalendar.DateChanged += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateChanged);
//
// ctxMenuAppointments // ctxMenuAppointments
// //
this.ctxMenuAppointments.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ctxMenuAppointments.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -103,54 +92,11 @@
this.mnuItemReplyAllEmail.Text = "Reply All With Email"; this.mnuItemReplyAllEmail.Text = "Reply All With Email";
this.mnuItemReplyAllEmail.Click += new System.EventHandler(this.mnuItemReplyAllEmail_Click); this.mnuItemReplyAllEmail.Click += new System.EventHandler(this.mnuItemReplyAllEmail_Click);
// //
// hdrDate
//
this.hdrDate.Text = "Date";
this.hdrDate.Width = 78;
//
// hdrSubject
//
this.hdrSubject.Text = "Subject";
this.hdrSubject.Width = 163;
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.hdrDate,
this.hdrSubject});
this.listView1.ContextMenuStrip = this.ctxMenuAppointments;
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.Font = new System.Drawing.Font("Calibri", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.listView1.FullRowSelect = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new System.Drawing.Size(289, 507);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnRefresh);
this.groupBox1.Controls.Add(this.lblRangeDays);
this.groupBox1.Controls.Add(this.numRangeDays);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox1.Location = new System.Drawing.Point(0, 207);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(289, 53);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Days:";
//
// btnRefresh // btnRefresh
// //
this.btnRefresh.Location = new System.Drawing.Point(162, 20); this.btnRefresh.Location = new System.Drawing.Point(110, 28);
this.btnRefresh.Name = "btnRefresh"; this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(75, 23); this.btnRefresh.Size = new System.Drawing.Size(66, 24);
this.btnRefresh.TabIndex = 4; this.btnRefresh.TabIndex = 4;
this.btnRefresh.Text = "Refresh"; this.btnRefresh.Text = "Refresh";
this.btnRefresh.UseVisualStyleBackColor = true; this.btnRefresh.UseVisualStyleBackColor = true;
@ -159,26 +105,93 @@
// panel1 // panel1
// //
this.panel1.Controls.Add(this.listView1); this.panel1.Controls.Add(this.listView1);
this.panel1.Controls.Add(this.grpRefresh);
this.panel1.Controls.Add(this.apptCalendar);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 260); this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1"; this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(289, 507); this.panel1.Size = new System.Drawing.Size(226, 815);
this.panel1.TabIndex = 8; this.panel1.TabIndex = 8;
// //
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.ContextMenuStrip = this.ctxMenuAppointments;
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.Font = new System.Drawing.Font("Segoe UI", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.listView1.FullRowSelect = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.Location = new System.Drawing.Point(0, 308);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new System.Drawing.Size(226, 507);
this.listView1.TabIndex = 4;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
//
// columnHeader1
//
this.columnHeader1.Text = "Date";
this.columnHeader1.Width = 78;
//
// columnHeader2
//
this.columnHeader2.Text = "Subject";
this.columnHeader2.Width = 163;
//
// grpRefresh
//
this.grpRefresh.Controls.Add(this.btnRefresh);
this.grpRefresh.Controls.Add(this.lblRangeDays);
this.grpRefresh.Controls.Add(this.numRangeDays);
this.grpRefresh.Dock = System.Windows.Forms.DockStyle.Top;
this.grpRefresh.Location = new System.Drawing.Point(0, 242);
this.grpRefresh.Name = "grpRefresh";
this.grpRefresh.Size = new System.Drawing.Size(226, 66);
this.grpRefresh.TabIndex = 3;
this.grpRefresh.TabStop = false;
this.grpRefresh.Text = "Days:";
//
// apptCalendar
//
this.apptCalendar.BoldedDates = null;
this.apptCalendar.CurrentMonthForeColor = System.Drawing.Color.Black;
this.apptCalendar.Dock = System.Windows.Forms.DockStyle.Top;
this.apptCalendar.FirstDayOfWeek = System.DayOfWeek.Sunday;
this.apptCalendar.Font = new System.Drawing.Font("Segoe UI", 7.8F);
this.apptCalendar.HoverBackColor = System.Drawing.Color.LightCyan;
this.apptCalendar.HoverForeColor = System.Drawing.Color.Black;
this.apptCalendar.Location = new System.Drawing.Point(0, 0);
this.apptCalendar.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.apptCalendar.Name = "apptCalendar";
this.apptCalendar.OtherMonthForeColor = System.Drawing.Color.LightGray;
this.apptCalendar.SelectedBackColor = System.Drawing.Color.LightBlue;
this.apptCalendar.SelectedDate = new System.DateTime(2013, 4, 26, 0, 0, 0, 0);
this.apptCalendar.SelectedForeColor = System.Drawing.Color.Blue;
this.apptCalendar.Size = new System.Drawing.Size(226, 242);
this.apptCalendar.TabIndex = 1;
this.apptCalendar.TodayBackColor = System.Drawing.Color.Blue;
this.apptCalendar.TodayForeColor = System.Drawing.Color.White;
this.apptCalendar.CellDoubleClick += new System.EventHandler(this.apptCalendar_CellDoubleClick);
this.apptCalendar.SelectedDateChanged += new System.EventHandler(this.apptCalendar_SelectedDateChanged);
//
// AppointmentsControl // AppointmentsControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.groupBox1); this.Font = new System.Drawing.Font("Segoe UI", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Controls.Add(this.apptCalendar);
this.Name = "AppointmentsControl"; this.Name = "AppointmentsControl";
this.Size = new System.Drawing.Size(289, 767); this.Size = new System.Drawing.Size(226, 815);
((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).EndInit();
this.ctxMenuAppointments.ResumeLayout(false); this.ctxMenuAppointments.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.grpRefresh.ResumeLayout(false);
this.grpRefresh.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -187,15 +200,15 @@
private System.Windows.Forms.NumericUpDown numRangeDays; private System.Windows.Forms.NumericUpDown numRangeDays;
private System.Windows.Forms.Label lblRangeDays; private System.Windows.Forms.Label lblRangeDays;
private DoubleClickMonthCalendar apptCalendar;
private System.Windows.Forms.ContextMenuStrip ctxMenuAppointments; private System.Windows.Forms.ContextMenuStrip ctxMenuAppointments;
private System.Windows.Forms.ToolStripMenuItem mnuItemReplyAllEmail; private System.Windows.Forms.ToolStripMenuItem mnuItemReplyAllEmail;
private System.Windows.Forms.ColumnHeader hdrDate;
private System.Windows.Forms.ColumnHeader hdrSubject;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnRefresh; private System.Windows.Forms.Button btnRefresh;
private CustomCalendar apptCalendar;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.GroupBox grpRefresh;
} }

View File

@ -48,7 +48,7 @@ namespace Outlook2013TodoAddIn
/// </summary> /// </summary>
/// <param name="sender">Sender</param> /// <param name="sender">Sender</param>
/// <param name="e">DateRangeEventArgs</param> /// <param name="e">DateRangeEventArgs</param>
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) private void apptCalendar_SelectedDateChanged(object sender, EventArgs e)
{ {
this.RetrieveAppointments(); this.RetrieveAppointments();
} }
@ -85,8 +85,8 @@ namespace Outlook2013TodoAddIn
Outlook.OlDefaultFolders.olFolderCalendar) Outlook.OlDefaultFolders.olFolderCalendar)
as Outlook.Folder; as Outlook.Folder;
int selectedMonth = this.apptCalendar.SelectionStart.Month; int selectedMonth = this.apptCalendar.SelectedDate.Month;
int selectedYear = this.apptCalendar.SelectionStart.Year; int selectedYear = this.apptCalendar.SelectedDate.Year;
// To get all the appointments for the current month (so it displays nicely bolded even for past events) // To get all the appointments for the current month (so it displays nicely bolded even for past events)
DateTime start = new DateTime(selectedYear, selectedMonth, 1); // MM-01-YYYY DateTime start = new DateTime(selectedYear, selectedMonth, 1); // MM-01-YYYY
@ -107,10 +107,10 @@ namespace Outlook2013TodoAddIn
} }
// Highlight dates with appointments in the current calendar // Highlight dates with appointments in the current calendar
this.apptCalendar.BoldedDates = appts.Select<Outlook.AppointmentItem, DateTime>(a => a.Start).ToArray(); this.apptCalendar.BoldedDates = appts.Select<Outlook.AppointmentItem, DateTime>(a => a.Start.Date).Distinct().ToArray();
// Now display the actual appointments below the calendar // Now display the actual appointments below the calendar
DateTime startRange = this.apptCalendar.SelectionStart; DateTime startRange = this.apptCalendar.SelectedDate;
DateTime endRange = startRange.AddDays((int)this.numRangeDays.Value); DateTime endRange = startRange.AddDays((int)this.numRangeDays.Value);
// Get items in range // Get items in range
@ -169,6 +169,8 @@ namespace Outlook2013TodoAddIn
this.listView1.Items.Clear(); this.listView1.Items.Clear();
this.listView1.Items.AddRange(lstCol.ToArray()); this.listView1.Items.AddRange(lstCol.ToArray());
this.apptCalendar.UpdateCalendar();
} }
/// <summary> /// <summary>
@ -291,7 +293,7 @@ namespace Outlook2013TodoAddIn
/// </summary> /// </summary>
/// <param name="sender">Sender</param> /// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param> /// <param name="e">EventArgs</param>
private void apptCalendar_DoubleClickEx(object sender, EventArgs e) private void apptCalendar_CellDoubleClick(object sender, EventArgs e)
{ {
// Clicking in days outside of the current month will cause the calendar to refresh to that day // Clicking in days outside of the current month will cause the calendar to refresh to that day
// reposition all days and select the wrong one // reposition all days and select the wrong one
@ -299,9 +301,10 @@ namespace Outlook2013TodoAddIn
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = f; Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = f;
Outlook.CalendarView cv = (Outlook.CalendarView)(Globals.ThisAddIn.Application.ActiveExplorer().CurrentView); Outlook.CalendarView cv = (Outlook.CalendarView)(Globals.ThisAddIn.Application.ActiveExplorer().CurrentView);
cv.CalendarViewMode = Outlook.OlCalendarViewMode.olCalendarViewDay; cv.CalendarViewMode = Outlook.OlCalendarViewMode.olCalendarViewDay;
cv.GoToDate(this.apptCalendar.SelectionStart); cv.GoToDate(this.apptCalendar.SelectedDate);
} }
#endregion "Methods" #endregion "Methods"
} }
} }

View File

@ -0,0 +1,133 @@
namespace Outlook2013TodoAddIn
{
partial class CustomCalendar
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnPrevious = new System.Windows.Forms.Button();
this.btnNext = new System.Windows.Forms.Button();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.lnkCurrentRange = new System.Windows.Forms.LinkLabel();
this.lnkToday = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// btnPrevious
//
this.btnPrevious.Location = new System.Drawing.Point(9, 8);
this.btnPrevious.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnPrevious.Name = "btnPrevious";
this.btnPrevious.Size = new System.Drawing.Size(31, 26);
this.btnPrevious.TabIndex = 0;
this.btnPrevious.Text = "<";
this.btnPrevious.UseVisualStyleBackColor = true;
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(213, 8);
this.btnNext.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(31, 26);
this.btnNext.TabIndex = 2;
this.btnNext.Text = ">";
this.btnNext.UseVisualStyleBackColor = true;
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 7;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28572F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28572F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28572F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28572F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28572F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 14.28572F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(9, 38);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 7;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 14.28571F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(234, 181);
this.tableLayoutPanel1.TabIndex = 3;
//
// lnkCurrentRange
//
this.lnkCurrentRange.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
this.lnkCurrentRange.Location = new System.Drawing.Point(47, 8);
this.lnkCurrentRange.Name = "lnkCurrentRange";
this.lnkCurrentRange.Size = new System.Drawing.Size(159, 26);
this.lnkCurrentRange.TabIndex = 0;
this.lnkCurrentRange.TabStop = true;
this.lnkCurrentRange.Text = "lnkCurrentRange";
this.lnkCurrentRange.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lnkToday
//
this.lnkToday.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
this.lnkToday.Location = new System.Drawing.Point(9, 221);
this.lnkToday.Name = "lnkToday";
this.lnkToday.Size = new System.Drawing.Size(234, 26);
this.lnkToday.TabIndex = 4;
this.lnkToday.TabStop = true;
this.lnkToday.Text = "lnkToday";
this.lnkToday.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lnkToday.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkToday_LinkClicked);
//
// CustomCalendar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lnkToday);
this.Controls.Add(this.lnkCurrentRange);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnPrevious);
this.Font = new System.Drawing.Font("Calibri", 9F);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "CustomCalendar";
this.Size = new System.Drawing.Size(256, 257);
this.Load += new System.EventHandler(this.CustomCalendar_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnPrevious;
private System.Windows.Forms.Button btnNext;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.LinkLabel lnkCurrentRange;
private System.Windows.Forms.LinkLabel lnkToday;
}
}

View File

@ -0,0 +1,428 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Outlook2013TodoAddIn
{
/// <summary>
/// Custom calendar control with more flexibility and better skinning control
/// </summary>
public partial class CustomCalendar : UserControl
{
#region "Variables"
/// <summary>
/// Used to keep track of the currently selected Date
/// </summary>
DateTime _selectedDate = DateTime.Today;
#endregion "Variables"
#region "Properties"
/// <summary>
/// Gets/sets the current date
/// </summary>
public DateTime SelectedDate
{
get
{
return _selectedDate;
}
set
{
if (_selectedDate != value)
{
_selectedDate = value;
// this.UpdateCalendar();
this.OnSelectedDateChanged(EventArgs.Empty);
}
}
}
/// <summary>
/// Gets/sets the first day of week
/// </summary>
public DayOfWeek FirstDayOfWeek { get; set; }
/// <summary>
/// Set of dates to display in BOLD
/// </summary>
public DateTime[] BoldedDates { get; set; }
/// <summary>
/// Gets/sets font color of dates for current month
/// </summary>
public Color CurrentMonthForeColor { get; set; }
/// <summary>
/// Gets/sets font color of dates for other months (previous/next)
/// </summary>
public Color OtherMonthForeColor { get; set; }
/// <summary>
/// Gets/sets font color for today's date
/// </summary>
public Color TodayForeColor { get; set; }
/// <summary>
/// Gets/sets back color for today's date
/// </summary>
public Color TodayBackColor { get; set; }
/// <summary>
/// Gets/sets font color for selected's date
/// </summary>
public Color SelectedForeColor { get; set; }
/// <summary>
/// Gets/sets back color for selected's date
/// </summary>
public Color SelectedBackColor { get; set; }
/// <summary>
/// Gets/sets font color when mouse over a cell
/// </summary>
public Color HoverForeColor { get; set; }
/// <summary>
/// Gets/sets back color when mouse over a cell
/// </summary>
public Color HoverBackColor { get; set; }
#endregion "Properties"
#region "Methods"
/// <summary>
/// Default constructor
/// </summary>
public CustomCalendar()
{
InitializeComponent();
//this.SelectedDate = DateTime.Today;
this.FirstDayOfWeek = DayOfWeek.Sunday;
//TODO: Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek
this.CurrentMonthForeColor = Color.Black;
this.OtherMonthForeColor = Color.LightGray;
this.TodayForeColor = Color.White;
this.TodayBackColor = Color.Blue;
this.SelectedForeColor = Color.Blue;
this.SelectedBackColor = Color.LightBlue;
this.HoverForeColor = Color.Black;
this.HoverBackColor = Color.LightCyan;
this.CreateTableControls();
}
/// <summary>
/// Paint the month upon initial load
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void CustomCalendar_Load(object sender, EventArgs e)
{
// TODO: check initial double firing
// TODO: Mark dates with colors from outlook
this.UpdateCalendar();
}
/// <summary>
/// Creates all inner labels once to be updated when the calendar changes
/// </summary>
private void CreateTableControls()
{
this.tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
for (int row = 0; row < this.tableLayoutPanel1.RowCount; row++)
{
for (int col = 0; col < this.tableLayoutPanel1.ColumnCount; col++)
{
Label lblCtrl = new Label() { Text = "xx" };
lblCtrl.Name = String.Format("lbl_{0}_{1}", col.ToString(), row.ToString());
lblCtrl.Dock = DockStyle.Fill;
lblCtrl.TextAlign = ContentAlignment.MiddleCenter;
lblCtrl.Margin = Padding.Empty;
lblCtrl.Padding = Padding.Empty;
lblCtrl.FlatStyle = FlatStyle.Flat;
if (row != 0)
{
lblCtrl.MouseEnter += lblCtrl_MouseEnter;
lblCtrl.MouseLeave += lblCtrl_MouseLeave;
lblCtrl.Click += lblCtrl_Click; // TODO: If we disable this, then we can't select a date...
lblCtrl.DoubleClick += lblCtrl_DoubleClick;
}
this.tableLayoutPanel1.Controls.Add(lblCtrl);
this.tableLayoutPanel1.SetCellPosition(lblCtrl, new TableLayoutPanelCellPosition(col, row));
}
}
}
/// <summary>
/// Changes labels according to the currently displayed month
/// </summary>
public void UpdateCalendar()
{
// All controls are previously created, just need to update labels, etc...
this.lnkCurrentRange.Text = this.SelectedDate.ToString("MMM yyyy");
this.lnkToday.Text = "Today: " + DateTime.Today.ToShortDateString();
string[] daysOfWeek = Enum.GetNames(typeof(DayOfWeek));
string sFirstDayOfWeek = Enum.GetName(typeof(DayOfWeek), this.FirstDayOfWeek);
List<string> sortedDays = new List<string>();
sortedDays.AddRange(daysOfWeek.SkipWhile(ow => ow != sFirstDayOfWeek));
sortedDays.AddRange(daysOfWeek.TakeWhile(ow => ow != sFirstDayOfWeek));
int dayCurrent = 0;
int firstIndex = 0;
DateTime firstOfCurrentMonth = new DateTime(this.SelectedDate.Year, this.SelectedDate.Month, 1);
DateTime previousMonth = firstOfCurrentMonth.AddMonths(-1);
DateTime nextMonth = firstOfCurrentMonth.AddMonths(1);
int daysInPreviousMonth = DateTime.DaysInMonth(previousMonth.Year, previousMonth.Month);
int daysInCurrentMonth = DateTime.DaysInMonth(this.SelectedDate.Year, this.SelectedDate.Month);
for (int col = 0; col < this.tableLayoutPanel1.ColumnCount; col++)
{
if (sortedDays[col] == Enum.GetName(typeof(DayOfWeek), firstOfCurrentMonth.DayOfWeek))
{
firstIndex = col; // Get the position of day 1 of the current month
}
Label lblDay = this.tableLayoutPanel1.GetControlFromPosition(col, 0) as Label;
lblDay.Text = sortedDays[col].Substring(0, 2).ToUpper();
}
dayCurrent = daysInPreviousMonth - firstIndex + 1;
if (dayCurrent > daysInPreviousMonth)
{
dayCurrent = daysInPreviousMonth - 6;
}
bool previousMonthVisible = (dayCurrent != 1);
bool nextMonthVisible = false;
// Row 0 is for days of week
for (int row = 1; row < this.tableLayoutPanel1.RowCount; row++)
{
for (int col = 0; col < this.tableLayoutPanel1.ColumnCount; col++)
{
Label lblCtrl = this.tableLayoutPanel1.GetControlFromPosition(col, row) as Label;
lblCtrl.Text = dayCurrent.ToString();
DateTime embeddedDate;
Font displayFont;
Color foreColor;
Color backColor = this.BackColor;
BorderStyle borderStyle = BorderStyle.None;
// Customize the days
if (previousMonthVisible)
{
embeddedDate = new DateTime(previousMonth.Year, previousMonth.Month, dayCurrent);
displayFont = this.Font;
foreColor = this.OtherMonthForeColor;
}
else if (nextMonthVisible)
{
embeddedDate = new DateTime(nextMonth.Year, nextMonth.Month, dayCurrent);
displayFont = this.Font;
foreColor = this.OtherMonthForeColor;
}
else // Current month
{
embeddedDate = new DateTime(this.SelectedDate.Year, this.SelectedDate.Month, dayCurrent);
displayFont = this.Font;
foreColor = this.CurrentMonthForeColor;
}
if (this.BoldedDates != null && this.BoldedDates.Contains(embeddedDate))
{
displayFont = new Font(this.Font, FontStyle.Bold);
}
if (embeddedDate == DateTime.Today)
{
foreColor = this.TodayForeColor;
backColor = this.TodayBackColor;
}
else if (embeddedDate == this.SelectedDate)
{
borderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
foreColor = this.SelectedForeColor;
backColor = this.SelectedBackColor;
}
lblCtrl.Tag = embeddedDate;
lblCtrl.Font = displayFont;
lblCtrl.ForeColor = foreColor;
lblCtrl.BackColor = backColor;
lblCtrl.BorderStyle = borderStyle;
dayCurrent++;
if (previousMonthVisible && dayCurrent > daysInPreviousMonth)
{
dayCurrent = 1; // Start current month
previousMonthVisible = false;
}
if (!previousMonthVisible && dayCurrent > daysInCurrentMonth)
{
dayCurrent = 1; // Start next month
nextMonthVisible = true;
}
}
}
}
/// <summary>
/// Returns to the previous month
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void btnPrevious_Click(object sender, EventArgs e)
{
this.SelectedDate = this.SelectedDate.AddMonths(-1);
//this.UpdateCalendar();
}
/// <summary>
/// Advances to the next month
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void btnNext_Click(object sender, EventArgs e)
{
this.SelectedDate = this.SelectedDate.AddMonths(1);
//this.UpdateCalendar();
}
/// <summary>
/// Change background color of the label
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void lblCtrl_MouseEnter(object sender, EventArgs e)
{
Label lblCtrl = sender as Label;
DateTime curDate = (DateTime)lblCtrl.Tag;
if (curDate.Month == this.SelectedDate.Month && curDate.Year == this.SelectedDate.Year)
{
lblCtrl.ForeColor = this.HoverForeColor;
}
else
{
lblCtrl.ForeColor = this.OtherMonthForeColor;
}
//lblCtrl.ForeColor = this.HoverForeColor;
lblCtrl.BackColor = this.HoverBackColor;
}
/// <summary>
/// Change background color of the label
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void lblCtrl_MouseLeave(object sender, EventArgs e)
{
Label lblCtrl = sender as Label;
DateTime curDate = (DateTime)lblCtrl.Tag;
if (curDate == DateTime.Today)
{
lblCtrl.ForeColor = this.TodayForeColor;
lblCtrl.BackColor = this.TodayBackColor;
}
else if (curDate == this.SelectedDate)
{
lblCtrl.ForeColor = this.SelectedForeColor;
lblCtrl.BackColor = this.SelectedBackColor;
}
else
{
if (curDate.Month == this.SelectedDate.Month && curDate.Year == this.SelectedDate.Year)
{
lblCtrl.ForeColor = this.CurrentMonthForeColor;
}
else
{
lblCtrl.ForeColor = this.OtherMonthForeColor;
}
lblCtrl.BackColor = this.BackColor;
}
}
/// <summary>
/// Sets the currently selected day
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void lblCtrl_Click(object sender, EventArgs e)
{
this.SelectedDate = (DateTime)(sender as Label).Tag;
//this.UpdateCalendar();
}
/// <summary>
/// Event handler to subscribe to
/// </summary>
public event EventHandler CellDoubleClick;
/// <summary>
/// Fires the attached event handler
/// </summary>
/// <param name="e">EventArgs</param>
protected virtual void OnCellDoubleClick(EventArgs e)
{
EventHandler handler = CellDoubleClick;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Fires the double-click event on any given day label
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">EventArgs</param>
private void lblCtrl_DoubleClick(object sender, EventArgs e)
{
this.SelectedDate = (DateTime)(sender as Label).Tag;
OnCellDoubleClick(EventArgs.Empty);
}
/// <summary>
/// Event handler to subscribe to
/// </summary>
public event EventHandler SelectedDateChanged;
/// <summary>
/// Fires the attached event handler
/// </summary>
/// <param name="e">EventArgs</param>
protected virtual void OnSelectedDateChanged(EventArgs e)
{
EventHandler handler = SelectedDateChanged;
if (handler != null)
{
handler(this, e);
}
}
/// <summary>
/// Select today's date in the calendar
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">LinkLabelLinkClickedEventArgs</param>
private void lnkToday_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.SelectedDate = DateTime.Today;
//this.UpdateCalendar();
}
#endregion "Methods"
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Outlook2013TodoAddIn
{
public class DoubleClickMonthCalendar : MonthCalendar
{
public event EventHandler DoubleClickEx;
public DoubleClickMonthCalendar()
{
lastClickTick = Environment.TickCount - SystemInformation.DoubleClickTime;
}
protected override void OnMouseDown(MouseEventArgs e)
{
int tick = Environment.TickCount;
if (tick - lastClickTick <= SystemInformation.DoubleClickTime)
{
EventHandler handler = DoubleClickEx;
if (handler != null) handler(this, EventArgs.Empty);
}
else
{
base.OnMouseDown(e);
lastClickTick = tick;
}
}
private int lastClickTick;
}
}

View File

@ -183,8 +183,11 @@
can be found. can be found.
--> -->
<ItemGroup> <ItemGroup>
<Compile Include="DoubleClickMonthCalendar.cs"> <Compile Include="CustomCalendar.cs">
<SubType>Component</SubType> <SubType>UserControl</SubType>
</Compile>
<Compile Include="CustomCalendar.Designer.cs">
<DependentUpon>CustomCalendar.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="FormRecurringOpen.cs"> <Compile Include="FormRecurringOpen.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
@ -214,6 +217,9 @@
<Compile Include="TodoRibbonAddIn.Designer.cs"> <Compile Include="TodoRibbonAddIn.Designer.cs">
<DependentUpon>TodoRibbonAddIn.cs</DependentUpon> <DependentUpon>TodoRibbonAddIn.cs</DependentUpon>
</Compile> </Compile>
<EmbeddedResource Include="CustomCalendar.resx">
<DependentUpon>CustomCalendar.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormRecurringOpen.resx"> <EmbeddedResource Include="FormRecurringOpen.resx">
<DependentUpon>FormRecurringOpen.cs</DependentUpon> <DependentUpon>FormRecurringOpen.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>