using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GrapeCity.Win.CalendarGrid;
namespace CalendarGridSampleCode
{
public class AppointmentCellDemo : Form
{
private GcCalendarGrid gcCalendarGrid = new GcCalendarGrid();
public AppointmentCellDemo()
{
this.Text = "AppointmentCell Demo";
this.Size = new Size(800, 700);
this.StartPosition = FormStartPosition.CenterScreen;
this.Load += AppointmentCellDemo_Load;
this.gcCalendarGrid.Template = this.CreateTemplate();
this.gcCalendarGrid.FirstDateInView = new DateTime(2014, 1, 1);
this.gcCalendarGrid.AppointmentCellDragging += gcCalendarGrid_AppointmentCellDragging;
// Add GcCalendarGrid to form
this.gcCalendarGrid.Dock = DockStyle.Fill;
this.Controls.Add(this.gcCalendarGrid);
}
void AppointmentCellDemo_Load(object sender, EventArgs e)
{
this.gcCalendarGrid[new DateTime(2014, 1, 12)][1, 0].Value = "You have an appointment between these days.";
this.gcCalendarGrid[new DateTime(2014, 1, 12)][1, 0].ColumnSpan = 5;
AngleBracketShapeRenderer render = new AngleBracketShapeRenderer();
render.ArrowLength = 15;
render.FillColor = Color.GreenYellow;
render.LineColor = Color.Orange;
render.LineStyle = CalendarShapeLineStyle.Thin;
render.LineWidth = 2;
(this.gcCalendarGrid[DateTime.Today][1, 0].CellType as CalendarAppointmentCellType).Renderer = render;
}
void gcCalendarGrid_AppointmentCellDragging(object sender, AppointmentCellDraggingEventArgs e)
{
//The following code will make the appointment limited between 2014/1/1 and 2014/1/31, and the original appointment date cannot be changed to shorter.
if (e.StartCellPosition.RowIndex == 1 && e.StartCellPosition.ColumnIndex == 0)
{
if (e.DraggingHandle == HandlePosition.Left)
{
if (e.TargetCellPosition.Date >= new DateTime(2014, 1, 1) && e.TargetCellPosition.Date <= e.StartCellPosition.Date)
{
e.AllowDrop = true;
}
else
{
e.AllowDrop = false;
}
}
else if(e.DraggingHandle == HandlePosition.Right)
{
if (e.TargetCellPosition.Date <= new DateTime(2014, 1, 31) && e.TargetCellPosition.Date >= e.EndCellPosition.Date)
{
e.AllowDrop = true;
}
else
{
e.AllowDrop = false;
}
}
}
}
private CalendarTemplate CreateTemplate()
{
GrapeCity.Win.CalendarGrid.CalendarTemplate calendarTemplate1 = new GrapeCity.Win.CalendarGrid.CalendarTemplate();
GrapeCity.Win.CalendarGrid.CalendarHeaderCellType calendarHeaderCellType1 = new GrapeCity.Win.CalendarGrid.CalendarHeaderCellType();
GrapeCity.Win.CalendarGrid.CalendarAppointmentCellType calendarAppointmentCellType1 = new GrapeCity.Win.CalendarGrid.CalendarAppointmentCellType();
calendarTemplate1.RowCount = 3;
calendarTemplate1.RowHeaderColumnCount = 0;
calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle";
calendarHeaderCellType1.SupportLocalization = true;
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1;
calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}";
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter;
calendarTemplate1.Content.CellStyleName = "defaultStyle";
calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日";
calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet;
calendarAppointmentCellType1.SupportLocalization = true;
calendarTemplate1.Content.GetCell(1, 0).CellType = calendarAppointmentCellType1;
calendarTemplate1.Content.GetCell(2, 0).DateFormat = "{Rokuyou}";
calendarTemplate1.Content.GetCell(2, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleRight;
return calendarTemplate1;
}
[STAThreadAttribute()]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new AppointmentCellDemo());
}
}
}
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports GrapeCity.Win.CalendarGrid
Namespace CalendarGridSampleCode
Public Class AppointmentCellDemo
Inherits Form
Private gcCalendarGrid As New GcCalendarGrid()
Public Sub New()
Me.Text = "AppointmentCell Demo"
Me.Size = New Size(800, 700)
Me.StartPosition = FormStartPosition.CenterScreen
AddHandler Me.Load, AddressOf AppointmentCellDemo_Load
Me.gcCalendarGrid.Template = Me.CreateTemplate()
Me.gcCalendarGrid.FirstDateInView = New DateTime(2014, 1, 1)
AddHandler Me.gcCalendarGrid.AppointmentCellDragging, AddressOf gcCalendarGrid_AppointmentCellDragging
' Add GcCalendarGrid to form
Me.gcCalendarGrid.Dock = DockStyle.Fill
Me.Controls.Add(Me.gcCalendarGrid)
End Sub
Private Sub AppointmentCellDemo_Load(sender As Object, e As EventArgs)
Me.gcCalendarGrid(New DateTime(2014, 1, 12))(1, 0).Value = "You have an appointment between these days."
Me.gcCalendarGrid(New DateTime(2014, 1, 12))(1, 0).ColumnSpan = 5
Dim render As New AngleBracketShapeRenderer()
render.ArrowLength = 15
render.FillColor = Color.GreenYellow
render.LineColor = Color.Orange
render.LineStyle = CalendarShapeLineStyle.Thin
render.LineWidth = 2
TryCast(Me.gcCalendarGrid(DateTime.Today)(1, 0).CellType, CalendarAppointmentCellType).Renderer = render
End Sub
Private Sub gcCalendarGrid_AppointmentCellDragging(sender As Object, e As AppointmentCellDraggingEventArgs)
'The following code will make the appointment limited between 2014/1/1 and 2014/1/31, and the original appointment date cannot be changed to shorter.
If e.StartCellPosition.RowIndex = 1 AndAlso e.StartCellPosition.ColumnIndex = 0 Then
If e.DraggingHandle = HandlePosition.Left Then
If e.TargetCellPosition.[Date] >= New DateTime(2014, 1, 1) AndAlso e.TargetCellPosition.[Date] <= e.StartCellPosition.[Date] Then
e.AllowDrop = True
Else
e.AllowDrop = False
End If
ElseIf e.DraggingHandle = HandlePosition.Right Then
If e.TargetCellPosition.[Date] <= New DateTime(2014, 1, 31) AndAlso e.TargetCellPosition.[Date] >= e.EndCellPosition.[Date] Then
e.AllowDrop = True
Else
e.AllowDrop = False
End If
End If
End If
End Sub
Private Function CreateTemplate() As CalendarTemplate
Dim calendarTemplate1 As New GrapeCity.Win.CalendarGrid.CalendarTemplate()
Dim calendarHeaderCellType1 As New GrapeCity.Win.CalendarGrid.CalendarHeaderCellType()
Dim calendarAppointmentCellType1 As New GrapeCity.Win.CalendarGrid.CalendarAppointmentCellType()
calendarTemplate1.RowCount = 3
calendarTemplate1.RowHeaderColumnCount = 0
calendarTemplate1.ColumnHeader.CellStyleName = "defaultStyle"
calendarHeaderCellType1.SupportLocalization = True
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellType = calendarHeaderCellType1
calendarTemplate1.ColumnHeader.GetCell(0, 0).DateFormat = "{DayOfWeek}"
calendarTemplate1.ColumnHeader.GetCell(0, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleCenter
calendarTemplate1.Content.CellStyleName = "defaultStyle"
calendarTemplate1.Content.GetCell(0, 0).DateFormat = "d日"
calendarTemplate1.Content.GetCell(0, 0).DateFormatType = GrapeCity.Win.CalendarGrid.CalendarDateFormatType.DotNet
calendarAppointmentCellType1.SupportLocalization = True
calendarTemplate1.Content.GetCell(1, 0).CellType = calendarAppointmentCellType1
calendarTemplate1.Content.GetCell(2, 0).DateFormat = "{Rokuyou}"
calendarTemplate1.Content.GetCell(2, 0).CellStyle.Alignment = GrapeCity.Win.CalendarGrid.CalendarGridContentAlignment.MiddleRight
Return calendarTemplate1
End Function
<STAThreadAttribute> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New AppointmentCellDemo())
End Sub
End Class
End Namespace