SuperAPI AI 工具集

syncfusion-winforms-scheduler

办公与效率

查看项目

更新于 10-16 02:14

技能介绍

组件概述

Syncfusion Windows Forms Scheduler 是一个功能完善的日历控件,提供类似 Microsoft Outlook 的日程管理功能,可创建、查看和管理约会。控件基于 Grid 控件构建,支持多种视图类型(月、日、周、工作周、自定义周),并支持周期性约会、拖放操作、触摸手势以及大量定制选项。

命名空间:Syncfusion.Windows.Forms.Schedule

主要组件包括:

  • ScheduleControl:包含所有排程功能的主用户控件
  • ScheduleAppointment:表示单个约会的数据对象
  • ScheduleDataProvider:数据管理与持久化的基类
  • NavigationCalendar:用于日期导航的多月日历
  • Caption Panel:导航按钮与标题显示
  • Navigation Panel:包含导航日历和自定义控件的侧边栏

视图类型包括:Month(月)、Day(日)、Week(周)、WorkWeek(工作周)、CustomWeek(自定义周)。

主要能力

视图与导航

支持以编程方式或通过上下文菜单切换视图;可配置导航日历(颜色、选中状态、今日标记);可定制导航面板与标题面板;支持周数显示与日历布局;提供日期导航与选择事件。

约会与数据管理

ScheduleAppointment 类提供以下属性:StartTime、EndTime、Subject、Content、AllDay、LabelValue、MarkerValue、ReminderValue、LocationValue、ForeColor、UniqueID、Owner。

ScheduleDataProvider 基类提供以下方法:GetScheduleForDay、GetSchedule、NewScheduleAppointment、AddItem、RemoveItem、CommitChanges,以及 SaveOnCloseBehaviorAction 自动保存行为。

数据接口包括:IScheduleAppointment、IScheduleAppointmentList、IScheduleDataProvider。

周期性约会

支持规则语法与格式,规则类型包括 Every DAY、WEEKDAY、WEEKEND、WEEK、MONTH、QUARTER、YEAR;支持基于时间的重复(Every SEC、Every MIN、Every HR);通过 AllowSecondsInAppointment 属性支持小于小时间隔;既可经约会对话框 UI 添加,也可通过 RecurrenceRule 属性以编程方式添加;提供 IRecurringScheduleAppointment 和 IRecurringScheduleDataProvider 接口。

外观定制

通过 Appearance 属性和 ScheduleAppearance 对象进行定制:边框自定义(ClickItemBorderColor、DragColor、SolidBorderColor)、标题与表头定制、日期与时间的显示格式字符串、导航日历外观(颜色、选中、今日标记)、Prime Time 配置(起止时间与颜色)、时间列定制(24 小时格式、字体大小、颜色)、视觉样式与 Metro 主题支持、ThemesEnabled 属性。

注意:订阅 ThemeChanged 事件需通过 scheduleControl1.GetScheduleHost().ThemeChanged,而非直接在 ScheduleControl 上订阅。

触摸与交互

通过 EnableTouchMode 属性启用触摸支持:垂直滑动滚动(Day/WorkWeek 视图)、水平滑动导航前后、缩放切换视图类型、约会拖动与调整大小、ItemChanging 事件与 ItemDragHitContext、ItemAction 枚举。在 ItemChanging 事件处理程序中应使用 e.ProposedItem 获取约会详情。

使用方式

安装与依赖

程序集依赖:

  • Syncfusion.Grid.Base.dll
  • Syncfusion.Grid.Windows.dll
  • Syncfusion.Schedule.Base.dll
  • Syncfusion.Schedule.Windows.dll
  • Syncfusion.Shared.Base.dll
  • Syncfusion.Tools.Windows.dll

NuGet 安装命令:

Install-Package Syncfusion.Schedule.Windows -Version *

快速开始示例

using System;
using System.Windows.Forms;
using Syncfusion.Schedule;
using Syncfusion.Windows.Forms.Schedule;

namespace SchedulerApp
{
    public partial class Form1 : Form
    {
        private ScheduleControl scheduleControl1;
        
        public Form1()
        {
            InitializeComponent();
            InitializeScheduler();
        }
        
        private void InitializeScheduler()
        {
            // Create ScheduleControl
            scheduleControl1 = new ScheduleControl();
            scheduleControl1.Location = new Point(20, 20);
            scheduleControl1.Size = new Size(800, 600);
            
            // Set up built-in data provider
            ArrayListDataProvider data = new ArrayListDataProvider();
            data.MasterList = new ArrayListAppointmentList();
            
            // Configure view and data binding
            scheduleControl1.ScheduleType = ScheduleViewType.Month;
            scheduleControl1.DataSource = data;
            
            // Add to form
            this.Controls.Add(scheduleControl1);
        }
    }
}

创建并添加约会

ArrayListDataProvider dataProvider = scheduleControl1.DataSource as ArrayListDataProvider;

IScheduleAppointment appointment = dataProvider.NewScheduleAppointment();
appointment.StartTime = DateTime.Now.AddHours(1);
appointment.EndTime = DateTime.Now.AddHours(2);
appointment.Subject = "Team Meeting";
appointment.Content = "Discuss project milestones";
appointment.LabelValue = 2; // Business category
appointment.ForeColor = Color.Blue;

dataProvider.AddItem(appointment);
scheduleControl1.Refresh();
dataProvider.SaveXML(dataProvider.FileName);

创建周期性约会

IScheduleDataProvider dataProvider = scheduleControl1.DataSource as IScheduleDataProvider;
IScheduleAppointment app = dataProvider.NewScheduleAppointment();
IRecurringScheduleDataProvider recurringProvider = scheduleControl1.DataSource as IRecurringScheduleDataProvider;

IRecurringScheduleAppointment recurringItem = app as IRecurringScheduleAppointment;

if (recurringItem != null)
{
    recurringItem.StartTime = new DateTime(2026, 03, 24, 9, 0, 0);
    recurringItem.EndTime = new DateTime(2026, 03, 24, 10, 0, 0);
    recurringItem.Subject = "Daily Standup";
    recurringItem.RecurrenceRule = "03/24/2026;06/30/2026;Every WEEKDAY";
    recurringProvider.AddNewRecurringAppointments(recurringItem, new DateTime(2026, 12, 31));
}

切换视图

scheduleControl1.ScheduleType = ScheduleViewType.Day;
scheduleControl1.ScheduleType = ScheduleViewType.Week;
scheduleControl1.ScheduleType = ScheduleViewType.WorkWeek;
scheduleControl1.ScheduleType = ScheduleViewType.Month;

定制外观

ScheduleAppearance appearance = scheduleControl1.Appearance;
appearance.CaptionBackColor = Color.FromArgb(0, 114, 198);
appearance.PrimeTimeCellColor = Color.LightBlue;
appearance.NonPrimeTimeCellColor = Color.White;
appearance.PrimeTimeStart = 9;
appearance.PrimeTimeEnd = 17;
appearance.VisualStyle = Syncfusion.Windows.Forms.GridVisualStyles.Metro;
appearance.NavigationCalendarBackColor = Color.White;
appearance.NavigationCalendarSelectionColor = Color.Blue;
appearance.NavigationCalendarTodayColor = Color.Red;

启用触摸支持

scheduleControl1.EnableTouchMode = true;

处理约会拖动事件

scheduleControl1.ItemChanging += ScheduleControl1_ItemChanging;

private void ScheduleControl1_ItemChanging(object sender, ScheduleAppointmentCancelEventArgs e)
{
    if (e.Action == ItemAction.ItemDrag)
    {
        Console.WriteLine($"Dropped in: {e.ItemDragHitContext}");
        if (e.ItemDragHitContext == ItemDragHitContext.Calendar)
        {
            MessageBox.Show("Cannot drop appointments in calendar area");
            e.Cancel = true;
        }
    }
}

适用场景

  • Outlook 风格日历应用:月视图配合导航日历、双击创建约会、拖放重新排程、周期性会议支持。
  • 资源排程系统:日/周视图用于资源分配、按资源类型颜色编码、拖放分配、自定义间隔时间槽管理。
  • 事件管理应用:月视图多日事件显示、全天事件支持、通过标签进行事件分类、自定义位置与提醒配置。
  • 医疗预约系统:工作周视图用于医生排班、15 分钟时间间隔、患者预约跟踪、周期性预约模式。
  • 时间跟踪与记录:通过 AllowSecondsInAppointment 实现分钟/秒精度、自定义数据提供程序集成数据库、基于时间的重复、详细时间列定制。
  • 支持触摸的平板排程:EnableTouchMode 用于平板设备、滑动导航日期、缩放手势切换视图、触摸友好的约会编辑。

相关技能

  • 实现数据网格(用于约会列表视图)
  • 实现日期选择器(用于日期选择 UI 组件)
  • 实现日历(用于独立日历组件)

限制

关于该控件的收费、价格、平台或具体效果等事实信息,资料中暂未提供。