PowerTools CalendarGrid for Windows Forms 1.0J
CalendarTemplate クラス
メンバ  使用例 

GcCalendarGrid のテンプレートを表します。
構文
Public Class CalendarTemplate 
public class CalendarTemplate 
解説

テンプレートは、GcCalendarGrid の日およびヘッダのレイアウトと外観を定義するために使用します。CalendarTemplate は、Content テーブル、RowHeader テーブル、ColumnHeader テーブル、CornerHeader テーブルの 4 つの CalendarTable で構成されています。

GcCalendarGridGcCalendarGrid.Item によって返される CalendarTable オブジェクトは Content テーブルからレイアウトと外観を継承し、GcCalendarGridGcCalendarGrid.RowHeaderGcCalendarGrid.ColumnHeaderGcCalendarGrid.CornerHeader の各テーブルはテンプレート内の関連するテーブルから継承します。

テンプレートはデザイナまたはコードによって設計できます。デザイナでは、セルを選択してプロパティを変更することにより、簡単にテンプレートを設計できます。コードを使用してテンプレートを設計するときは、CreateDefaultTemplate によって既定のテンプレートを作成するか、CalendarTemplate コンストラクタ(Int32,Int32) によって指定した行数と列数を持つ空のテンプレートを作成してから各セルのプロパティを変更します。

使用例
次のサンプルコードは、CalendarGrid のテンプレートの作成方法を示します。
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 TemplateDemo : Form
    {
        private GcCalendarGrid gcCalendarGrid1 = new GcCalendarGrid();
        private TableLayoutPanel tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
        private TableLayoutPanel tableLayoutPanel2 = new TableLayoutPanel();
        private Button button1 = new Button();
        private Button button2 = new Button();
        private Button button3 = new Button();
        private Button button4 = new Button();
        public TemplateDemo()
        {
            this.tableLayoutPanel1.ColumnCount = 1;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 2;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 90F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(554, 426);

            this.gcCalendarGrid1.Dock = DockStyle.Fill;
            this.tableLayoutPanel1.Controls.Add(this.gcCalendarGrid1, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 1);

            this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.button1.Text = "Use Empty Template";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += UseEmptyTemplate_Click;

            this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.button2.Text = "Use Default Template";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += UseDefaultTemplate_Click;

            this.button3.Dock = System.Windows.Forms.DockStyle.Fill;
            this.button3.Text = "Use Custom Template1";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += UseCustomTemplate1_Click;

            this.button4.Dock = System.Windows.Forms.DockStyle.Fill;
            this.button4.Text = "Use Custom Template2";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += UseCustomTemplate2_Click;

            this.tableLayoutPanel2.ColumnCount = 4;
            this.tableLayoutPanel2.RowCount = 1;
            this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25f));
            this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25f));
            this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25f));
            this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25f));
            this.tableLayoutPanel2.Controls.Add(this.button1, 0, 0);
            this.tableLayoutPanel2.Controls.Add(this.button2, 1, 0);
            this.tableLayoutPanel2.Controls.Add(this.button3, 2, 0);
            this.tableLayoutPanel2.Controls.Add(this.button4, 3, 0);
            this.tableLayoutPanel2.Dock = DockStyle.Fill;

            this.Text = "Template Demo";
            this.Size = new Size(800, 700);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.Controls.Add(this.tableLayoutPanel1);
        }

        private void UseEmptyTemplate_Click(object sender, EventArgs e)
        {
            this.UseEmptyTemplate();
        }

        private void UseDefaultTemplate_Click(object sender, EventArgs e)
        {
            this.UseDefaultTemplate();
        }

        private void UseCustomTemplate1_Click(object sender, EventArgs e)
        {
            this.UseCustomTemplate1();   
        }

        private void UseCustomTemplate2_Click(object sender, EventArgs e)
        {
            this.UseCustomTemplate2();
        }

        private void UseEmptyTemplate()
        {
            this.gcCalendarGrid1.CalendarView = new CalendarMonthView();
            this.gcCalendarGrid1.Template = new CalendarTemplate(0, 0, 0, 0);
        }

        private void UseDefaultTemplate()
        {
            this.gcCalendarGrid1.CalendarView = new CalendarMonthView();
            this.gcCalendarGrid1.Template = CalendarTemplate.CreateDefaultTemplate();
        }

        private void UseCustomTemplate1()
        {
            CalendarMonthView monthView = new CalendarMonthView();
            monthView.Dimensions = new Size(3, 4);
            monthView.MinScrollCount = 12;
            this.gcCalendarGrid1.CalendarView = monthView;
            
            CalendarTemplate template = CalendarTemplate.CreateDefaultTemplate();

            template.InsertColumnHeaderRow(0);
            template.ColumnHeader[0, 0].DateFormat = CalendarDateFormats.Month;
            template.ColumnHeader[0, 0].AutoMergeMode = AutoMergeMode.Horizontal;
            template.ColumnHeader[0, 0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;

            template.RowHeaderColumnCount = 1;
            template.RowHeader.Columns[0].Width = 30;
            template.RowHeader[0, 0].RowSpan = 4;
            template.RowHeader[0, 0].DateFormat = CalendarDateFormats.WeekNumber;
            template.RowHeader[0, 0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;

            template.Content[1, 0].RowSpan = 2;
            template.Content[1, 0].Value = "(Note)";
            
            this.gcCalendarGrid1.Template = template;

            this.gcCalendarGrid1.FirstDateInView = new DateTime(DateTime.Today.Year, 1, 1);
        }

        private void UseCustomTemplate2()
        {
            CalendarListView listView = new CalendarListView();
            listView.DayCount = 100;
            this.gcCalendarGrid1.CalendarView = listView;

            CalendarTemplate template = new CalendarTemplate(4, 1, 2, 2);

            template.ColumnHeader.CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
            template.ColumnHeader[0, 0].DateFormat = CalendarDateFormats.Month;
            template.ColumnHeader[0, 0].AutoMergeMode = AutoMergeMode.Horizontal;
            template.ColumnHeader[0, 0].AllowContentFloat = true;
            template.ColumnHeader[1, 0].DateFormat = CalendarDateFormats.Day;

            template.RowHeader.CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
            template.RowHeader.Columns[0].Width = 30;
            template.RowHeader.Columns[1].Width = 30;
            template.Content.Columns[0].Width = 30;

            template.RowHeader[0, 0].Value = "Active";
            template.RowHeader[0, 0].ColumnSpan = 2;
            CalendarCheckBoxCellType checkBoxCellType = new CalendarCheckBoxCellType();
            checkBoxCellType.CheckAlign = ContentAlignment.MiddleCenter;
            template.Content[0, 0].CellType = checkBoxCellType;
            template.Content.Rows[0].Height = 30;

            template.RowHeader[1, 0].Value = "Content";
            template.RowHeader[1, 0].RowSpan = 2;
            template.RowHeader[1, 0].CellStyle.TextVertical = CalendarGridTriState.True;
            template.RowHeader[1, 0].CellStyle.UseCompatibleTextRendering = CalendarGridTriState.True;
            template.RowHeader[1, 1].Value = "AM";
            template.RowHeader[2, 1].Value = "PM";

            template.Content[1, 0].CellStyle.Alignment = CalendarGridContentAlignment.TopCenter;
            template.Content[1, 0].CellStyle.TextVertical = CalendarGridTriState.True;
            template.Content[1, 0].CellStyle.UseCompatibleTextRendering = CalendarGridTriState.True;
            template.Content.Rows[1].Height = 150;

            template.Content[2, 0].CellStyle.Alignment = CalendarGridContentAlignment.TopCenter;
            template.Content[2, 0].CellStyle.TextVertical = CalendarGridTriState.True;
            template.Content[2, 0].CellStyle.UseCompatibleTextRendering = CalendarGridTriState.True;
            template.Content.Rows[2].Height = 150;

            template.RowHeader[3, 0].Value = "More";
            template.RowHeader[3, 0].ColumnSpan = 2;
            template.Content[3, 0].Value = "...";
            template.Content[3, 0].CellType = new CalendarButtonCellType();
            template.Content[3, 0].CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter;
            template.Content.Rows[0].Height = 30;

            this.gcCalendarGrid1.Template = template;
        }

        [STAThreadAttribute]
        public static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new TemplateDemo());
        }
    }
}
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 TemplateDemo
        Inherits Form
        Private gcCalendarGrid1 As New GcCalendarGrid()
        Private tableLayoutPanel1 As TableLayoutPanel = New System.Windows.Forms.TableLayoutPanel()
        Private tableLayoutPanel2 As New TableLayoutPanel()
        Private button1 As New Button()
        Private button2 As New Button()
        Private button3 As New Button()
        Private button4 As New Button()
        Public Sub New()
            Me.tableLayoutPanel1.ColumnCount = 1
            Me.tableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100.0F))
            Me.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.tableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
            Me.tableLayoutPanel1.Name = "tableLayoutPanel1"
            Me.tableLayoutPanel1.RowCount = 2
            Me.tableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 90.0F))
            Me.tableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10.0F))
            Me.tableLayoutPanel1.Size = New System.Drawing.Size(554, 426)

            Me.gcCalendarGrid1.Dock = DockStyle.Fill
            Me.tableLayoutPanel1.Controls.Add(Me.gcCalendarGrid1, 0, 0)
            Me.tableLayoutPanel1.Controls.Add(Me.tableLayoutPanel2, 0, 1)

            Me.button1.Dock = System.Windows.Forms.DockStyle.Fill
            Me.button1.Text = "Use Empty Template"
            Me.button1.UseVisualStyleBackColor = True
            AddHandler Me.button1.Click, AddressOf UseEmptyTemplate_Click

            Me.button2.Dock = System.Windows.Forms.DockStyle.Fill
            Me.button2.Text = "Use Default Template"
            Me.button2.UseVisualStyleBackColor = True
            AddHandler Me.button2.Click, AddressOf UseDefaultTemplate_Click

            Me.button3.Dock = System.Windows.Forms.DockStyle.Fill
            Me.button3.Text = "Use Custom Template1"
            Me.button3.UseVisualStyleBackColor = True
            AddHandler Me.button3.Click, AddressOf UseCustomTemplate1_Click

            Me.button4.Dock = System.Windows.Forms.DockStyle.Fill
            Me.button4.Text = "Use Custom Template2"
            Me.button4.UseVisualStyleBackColor = True
            AddHandler Me.button4.Click, AddressOf UseCustomTemplate2_Click

            Me.tableLayoutPanel2.ColumnCount = 4
            Me.tableLayoutPanel2.RowCount = 1
            Me.tableLayoutPanel2.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0F))
            Me.tableLayoutPanel2.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0F))
            Me.tableLayoutPanel2.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0F))
            Me.tableLayoutPanel2.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0F))
            Me.tableLayoutPanel2.Controls.Add(Me.button1, 0, 0)
            Me.tableLayoutPanel2.Controls.Add(Me.button2, 1, 0)
            Me.tableLayoutPanel2.Controls.Add(Me.button3, 2, 0)
            Me.tableLayoutPanel2.Controls.Add(Me.button4, 3, 0)
            Me.tableLayoutPanel2.Dock = DockStyle.Fill

            Me.Text = "Template Demo"
            Me.Size = New Size(800, 700)
            Me.StartPosition = FormStartPosition.CenterScreen
            Me.Controls.Add(Me.tableLayoutPanel1)
        End Sub

        Private Sub UseEmptyTemplate_Click(sender As Object, e As EventArgs)
            Me.UseEmptyTemplate()
        End Sub

        Private Sub UseDefaultTemplate_Click(sender As Object, e As EventArgs)
            Me.UseDefaultTemplate()
        End Sub

        Private Sub UseCustomTemplate1_Click(sender As Object, e As EventArgs)
            Me.UseCustomTemplate1()
        End Sub

        Private Sub UseCustomTemplate2_Click(sender As Object, e As EventArgs)
            Me.UseCustomTemplate2()
        End Sub

        Private Sub UseEmptyTemplate()
            Me.gcCalendarGrid1.CalendarView = New CalendarMonthView()
            Me.gcCalendarGrid1.Template = New CalendarTemplate(0, 0, 0, 0)
        End Sub

        Private Sub UseDefaultTemplate()
            Me.gcCalendarGrid1.CalendarView = New CalendarMonthView()
            Me.gcCalendarGrid1.Template = CalendarTemplate.CreateDefaultTemplate()
        End Sub

        Private Sub UseCustomTemplate1()
            Dim monthView As New CalendarMonthView()
            monthView.Dimensions = New Size(3, 4)
            monthView.MinScrollCount = 12
            Me.gcCalendarGrid1.CalendarView = monthView

            Dim template As CalendarTemplate = CalendarTemplate.CreateDefaultTemplate()

            template.InsertColumnHeaderRow(0)
            template.ColumnHeader(0, 0).DateFormat = CalendarDateFormats.Month
            template.ColumnHeader(0, 0).AutoMergeMode = AutoMergeMode.Horizontal
            template.ColumnHeader(0, 0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter

            template.RowHeaderColumnCount = 1
            template.RowHeader.Columns(0).Width = 30
            template.RowHeader(0, 0).RowSpan = 4
            template.RowHeader(0, 0).DateFormat = CalendarDateFormats.WeekNumber
            template.RowHeader(0, 0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter

            template.Content(1, 0).RowSpan = 2
            template.Content(1, 0).Value = "(Note)"

            Me.gcCalendarGrid1.Template = template

            Me.gcCalendarGrid1.FirstDateInView = New DateTime(DateTime.Today.Year, 1, 1)
        End Sub

        Private Sub UseCustomTemplate2()
            Dim listView As New CalendarListView()
            listView.DayCount = 100
            Me.gcCalendarGrid1.CalendarView = listView

            Dim template As New CalendarTemplate(4, 1, 2, 2)

            template.ColumnHeader.CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
            template.ColumnHeader(0, 0).DateFormat = CalendarDateFormats.Month
            template.ColumnHeader(0, 0).AutoMergeMode = AutoMergeMode.Horizontal
            template.ColumnHeader(0, 0).AllowContentFloat = True
            template.ColumnHeader(1, 0).DateFormat = CalendarDateFormats.Day

            template.RowHeader.CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
            template.RowHeader.Columns(0).Width = 30
            template.RowHeader.Columns(1).Width = 30
            template.Content.Columns(0).Width = 30

            template.RowHeader(0, 0).Value = "Active"
            template.RowHeader(0, 0).ColumnSpan = 2
            Dim checkBoxCellType As New CalendarCheckBoxCellType()
            checkBoxCellType.CheckAlign = ContentAlignment.MiddleCenter
            template.Content(0, 0).CellType = checkBoxCellType
            template.Content.Rows(0).Height = 30

            template.RowHeader(1, 0).Value = "Content"
            template.RowHeader(1, 0).RowSpan = 2
            template.RowHeader(1, 0).CellStyle.TextVertical = CalendarGridTriState.[True]
            template.RowHeader(1, 0).CellStyle.UseCompatibleTextRendering = CalendarGridTriState.[True]
            template.RowHeader(1, 1).Value = "AM"
            template.RowHeader(2, 1).Value = "PM"

            template.Content(1, 0).CellStyle.Alignment = CalendarGridContentAlignment.TopCenter
            template.Content(1, 0).CellStyle.TextVertical = CalendarGridTriState.[True]
            template.Content(1, 0).CellStyle.UseCompatibleTextRendering = CalendarGridTriState.[True]
            template.Content.Rows(1).Height = 150

            template.Content(2, 0).CellStyle.Alignment = CalendarGridContentAlignment.TopCenter
            template.Content(2, 0).CellStyle.TextVertical = CalendarGridTriState.[True]
            template.Content(2, 0).CellStyle.UseCompatibleTextRendering = CalendarGridTriState.[True]
            template.Content.Rows(2).Height = 150

            template.RowHeader(3, 0).Value = "More"
            template.RowHeader(3, 0).ColumnSpan = 2
            template.Content(3, 0).Value = "..."
            template.Content(3, 0).CellType = New CalendarButtonCellType()
            template.Content(3, 0).CellStyle.Alignment = CalendarGridContentAlignment.MiddleCenter
            template.Content.Rows(0).Height = 30

            Me.gcCalendarGrid1.Template = template
        End Sub

        <STAThreadAttribute> _
        Public Shared Sub Main()
            Application.EnableVisualStyles()
            Application.Run(New TemplateDemo())
        End Sub
    End Class
End Namespace
継承階層

System.Object
   GrapeCity.Win.CalendarGrid.CalendarTemplate

参照

CalendarTemplate メンバ
GrapeCity.Win.CalendarGrid 名前空間

 

 


© 2014 GrapeCity inc. All rights reserved.