📄 monthform.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using AnotherPDFLib;
using AnotherPDFLib.PdfTexts;
using AnotherPDFLib.PdfGraphics;
namespace AnotherPDFLibTest
{
public class MonthForm
{
static string[] MonthNames = new string[]{"", "January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November", "December"};
static DayOfWeek[] DayOfWeeks = new DayOfWeek[] {
DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday };
List<List<DateTime>> Weeks = new List<List<DateTime>>();
DateTime firstDay;
public MonthForm(int year, int month)
{
firstDay = new DateTime(year, month, 1);
int lastDay = firstDay.AddMonths(1).AddDays(-1).Day;
List<DateTime> week = null;
for (int day = 1; day <= lastDay; day++)
{
DateTime date = new DateTime(year, month, day);
if (week == null || date.DayOfWeek == DayOfWeek.Sunday)
{
week = new List<DateTime>();
Weeks.Add(week);
}
week.Add(date);
}
}
public void Render(PdfContentStream content, double x, double y)
{
Color blackColor = Color.Black;
Color yellowColor = Color.DarkKhaki;
Color redColor = Color.Brown;
//title
PdfMaker.DrawText(content, firstDay.Year.ToString(), x, y, StandardFont.CourierBold, 24, yellowColor, 100, RenderMode.Fill);
PdfMaker.DrawLine(content, x + 64, y + 6, 3, 200, yellowColor);
string monthName = MonthNames[firstDay.Month].ToUpper();
PdfMaker.DrawText(content, monthName, x + 80, y + 12, StandardFont.Helvetica, 18, blackColor, 100, RenderMode.Fill);
PdfMaker.DrawText(content, firstDay.Month.ToString(), x + 200, y + 12, StandardFont.HelveticaItalic, 36, redColor, 100, RenderMode.Fill);
//header
double yPos = y - 30;
double colWidth = 40;
double rowHeight = 30;
Color[] colors = new Color[] { redColor, blackColor, blackColor, blackColor, blackColor, blackColor, redColor };
for (int n = 0; n < DayOfWeeks.Length; n++)
{
DayOfWeek dayofweek = DayOfWeeks[n];
string weekName = dayofweek.ToString().ToUpper().Substring(0, 3);
PdfMaker.DrawText(content, weekName, x + colWidth * n, yPos, StandardFont.Helvetica, 14, colors[n], 100, RenderMode.Fill);
}
//days
yPos = y - 60;
foreach (List<DateTime> week in Weeks)
{
foreach (DateTime date in week)
{
int n = Array.IndexOf(DayOfWeeks, date.DayOfWeek);
PdfMaker.DrawText(content, String.Format("{0,2}", date.Day), x + 6 + colWidth * n, yPos, StandardFont.Helvetica, 14, colors[n], 100, RenderMode.Fill);
}
yPos -= rowHeight;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -